Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8117637

Label: setLabelFor() does not work dynamically

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • P3
    • Resolution: Fixed
    • 8
    • 8
    • javafx
    • Win 7, 8b61

    Description

      Sample to reproduce:

      import javafx.application.Application;
      import javafx.beans.value.ChangeListener;
      import javafx.beans.value.ObservableValue;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Label;
      import javafx.scene.control.RadioButton;
      import javafx.scene.control.ToggleGroup;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class Main extends Application {

          public static void main(String[] args) {
              Application.launch(args);
          }

          VBox root = new VBox();

          @Override
          public void start(final Stage stage) throws Exception {
              Scene scene = new Scene(root, 300, 300);
              final Label label = new Label("_Label");
              label.setMnemonicParsing(true);
              final Button button1 = new Button("Button1");
              final Button button2 = new Button("Button2");
              ToggleGroup group = new ToggleGroup();
              RadioButton rb1 = new RadioButton("setLabelFor(button1)");
              rb1.setToggleGroup(group);
              rb1.selectedProperty().addListener(new ChangeListener<Boolean>() {
                  public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
                      if (t1) {
                          label.setLabelFor(button1);
                      }
                  }
              });
              RadioButton rb2 = new RadioButton("setLabelFor(button2)");
              rb2.setToggleGroup(group);
              rb2.selectedProperty().addListener(new ChangeListener<Boolean>() {
                  public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
                      if (t1) {
                          label.setLabelFor(button2);
                      }
                  }
              });
              root.getChildren().addAll(label, button1, button2, rb1, rb2);
              stage.setScene(scene);
              stage.show();
          }
      }

      Attachments

        Issue Links

          Activity

            People

              miflemi Mick Fleming
              ogb Oleg Barbashov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported: