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

JavaFX Labels in Tab's VBox is not displayed until it is clicked

    Details

    • Type: Bug
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: 8u60, openjfx11, openjfx14
    • Fix Version/s: tbd
    • Component/s: javafx
    • Labels:

      Description

      ADDITIONAL SYSTEM INFORMATION :
      X86_64 /Linux ubuntu 16/jdk1.8.0_221 , jdk1.8.0_211, jdk1.8.0_66
      X86_64/Windows 10/jdk1.8.0_221

      A DESCRIPTION OF THE PROBLEM :
       Label which is in Tab's VBOX texts are not displayed correctly until we click the tab.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      /* How to reproduce the bug */
        1. compile this program ($javac TestTabLabel.java)
        2. start the test with jdk8_66 or later ($java8 TestTabLabel)
        3. click "Add TAB" button
        4. click "Add dummy rows"
        5. click "delete rows"
        6. select/focus "target tab" TAB by a mouse
        7. click "Add updated rows"

        We expect "dummy aaa changed." ..."dummy ddd changed." are displayed on the "target tab" TAB,
        but actually "dummy aaa" ... "dummy ddd" are displayed.
        But then we click "target tab" , the tab is repainted and "dummy aaa changed." ..."dummy ddd changed." are displayed.

      But if we follow the below instructions: ( changes the order 5 and 6 above, selecting 'target tab" before clicking delete raws)
       this bug is not seen.
        1. compile this program ($javac TestTabLabel.java)
        2. start the test with jdk8_66 or later ($java8 TestTabLabel)
        3. click "Add TAB" button
        4. click "Add dummy rows"
        5. select "target tab" TAB
        6. click "delete rows"
        7. click "Add updated rows"


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      In the Tab "target tab",
       dummy aaa changed.
       dummy bbb changed.
       dummy ccc changed.
       dummy ddd changed.
      is seen.

      ACTUAL -
      In the Tab "target tab",
       dummy aaa
       dummy bbb
       dummy ccc
       dummy ddd
      is seen until we click the tab.


      ---------- BEGIN SOURCE ----------
      import java.util.ArrayList;
      import java.util.List;

      import javafx.animation.KeyFrame;
      import javafx.animation.Timeline;
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Label;
      import javafx.scene.control.Tab;
      import javafx.scene.control.TabPane;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;
      import javafx.util.Duration;

      /* what is the bug
         A tab's contents of label's texts are not updated until we click/select the tab with a mouse
      */

      /* How to reproduce the bug
        1. compile this program ($javac TestTabLabel.java)
        2. start the test with jdk8_66 or later ($java8 TestTabLabel) on a x86 computer.
        3. click "Add TAB" button
        4. click "Add dummy rows"
        5. click "delete rows"
        6. select/focus "target tab" TAB by a mouse
        7. click "Add updated rows"

        We expect "dummy aaa changed." ..."dummy ddd changed." are displayed on the "target tab" TAB,
        but actually "dummy aaa" ... "dummy ddd" are displayed.
        But then we click "target tab" with a mouse, the tab is repainted and "dummy aaa changed." ..."dummy ddd changed." are displayed.

       And if we follow the below instructions: ( changes 5 and 6 order to above, selecting 'target tab" before clicking delete raws)
       this bug is not seen.
        1. compile this program ($javac TestTabLabel.java)
        2. start the test with jdk8_66 or later ($java8 TestTabLabel)
        3. click "Add TAB" button
        4. click "Add dummy rows"
        5. select "target tab" TAB
        6. click "delete rows"
        7. click "Add updated rows"

       */

      public class TestTabLabel0 extends Application {

          private HBox root;
          private TabPane tabPane;
          private Timeline timer;
          private Tab targetTab;

          private List<Label> labels = new ArrayList<>();

          @Override
          public void start(Stage primaryStage) throws Exception {

              root = new HBox();
              root.setPrefSize(400, 300);

              VBox menu = new VBox();
              root.getChildren().add(menu);

              {
                  Button button = new Button("Add TAB");
                  button.setOnAction(e -> {
                      labels.clear();
                      if (!tabPane.getTabs().contains(targetTab)) {
                          targetTab = new Tab();
                          targetTab.setText("target tab");
                          VBox box = new VBox();
                          targetTab.setContent(box);
                          tabPane.getTabs().add(targetTab);
                      }
                  });
                  menu.getChildren().add(button);
              }
              {
                  Button button = new Button("Remove TAB");
                  button.setOnAction(e -> {
                      tabPane.getTabs().remove(targetTab);
                  });
                  menu.getChildren().add(button);
              }
              {
                  Button button = new Button("Add dummy rows");
                  button.setOnAction(e -> onDummyRowAdd());
                  menu.getChildren().add(button);
              }
              {
                  Button button = new Button("delete rows");
                  button.setOnAction(e -> onRowRemove());
                  menu.getChildren().add(button);
              }
              {
                  Button button = new Button("Add updated rows");
                  button.setOnAction(e -> onRowAdd());
                  menu.getChildren().add(button);
              }

              tabPane = new TabPane();
              root.getChildren().add(tabPane);

              // initial tab (dummy)
              Tab dummyTab = new Tab();
              dummyTab.setText("dummy tab");
              VBox box = new VBox();
              dummyTab.setContent(box);
              tabPane.getTabs().add(dummyTab);

              Scene scene = new Scene(root);
              primaryStage.setScene(scene);
              primaryStage.show();
          }

          private void onDummyRowAdd() {

              VBox box = (VBox) targetTab.getContent();

              box.getChildren().add(new Label("dummy aaa"));
              box.getChildren().add(new Label("dummy bbb"));
              box.getChildren().add(new Label("dummy ccc"));
              box.getChildren().add(new Label("dummy ddd"));

              labels.clear();
          }

          private void onRowRemove() {

              VBox box = (VBox) targetTab.getContent();

              // evacuate labels on removing
              for (Object child : box.getChildren()) {
                  Label label = (Label) child;
                  labels.add(label);
              }

              box.getChildren().clear();
          }

          private int intervalCount = 0;

          private void onRowAdd() {
              intervalCount = 0;

              if (false) {// When this is 'false", labels shows as expected
      // updating labels in sequence without interval period.
                  interval();
                  intervalCount++;
                  interval();
                  intervalCount++;
                  interval();
                  intervalCount++;
                  interval();
                  intervalCount++;
              } else {
      // updating labels in sequence with interval period (500ms).
                  timer = new Timeline();
                  timer.getKeyFrames().add(new KeyFrame(new Duration(500)));

                  // Adding five raws from here
                  final int max = intervalCount + 4;
                  timer.setOnFinished(event -> {
                      interval();
                      intervalCount++;
                      if (intervalCount < max) {
                          timer.playFromStart();
                      } else {
                          // intervalCount = 0;
                  }
              }) ;
                  timer.playFromStart();
              }

          }

          private void interval() {
              VBox box = (VBox) targetTab.getContent();
      Label label = labels.get(intervalCount);

      if (!box.getChildren().contains(label)) {
      label.setText(label.getText() + " changed.");
      box.getChildren().add(label);
      }
          }

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

      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              arapte Ambarish Rapte
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: