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

Bound Label text not displayed when a graphic node is set.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: fx2.0
    • Fix Version/s: fx2.0.2
    • Component/s: javafx
    • Labels:
    • Environment:

      Mac OS X Lion, Mac beta - build 42.

      Description

      A Label control will not display both its text and its graphic if the text is bound to a string property and is not updated before the Scene is shown. The example code below illustrates the issue. When using setText and setGraphic, everything works fine.

      If the Label's textProperty is bound to a StringProperty AND a graphic is set, then the text will not be shown unless the StringProperty is initialized before the Scene is shown. If no graphic is set, then the text is updated properly regardless of when the update takes place.

      If the following code is run as-is, then no text will show up on the label.

      public class ProgressLabelTest extends Application {
          private SimpleStringProperty message = new SimpleStringProperty();

          @Override
          public void start(Stage stage) throws Exception {
              Rectangle r = new Rectangle(20, 20);
              Label l = new Label();

              // This shows both text and graphic - order doesn't matter.
      // l.setText("Hello, world");
      // l.setGraphic(r);

              // This shows both text and graphic as long as the text is
              // updated before the scene is shown
              l.textProperty().bind(message);
              l.setGraphic(r); // Comment this out and "Hello, world again" will show regardless of the next line
              //message.set("Hello, world (bound)"); // Uncomment this and "Hello, world again" will show

              Scene s = new Scene(new Group(l), 200, 200);
              stage.setScene(s);
              stage.show();

              message.set("Hello, world again (bound)");
          }

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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                leifs Leif Samuelsson (Inactive)
                Reporter:
                diversonjfx Dean Iverson (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported: