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

Issue in TabPaneSkin clone method : Cloning of label graphic is not working properly.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 8u20
    • 7u25
    • javafx
    • All

      Currently I am facing an issue in displaying the graphic of a label in the side menu of the TabPane control.
      The scenario is : I have set a graphic to a label ( Say "Label1"). I am setting this label (Label1) as a graphic to the Tab.

      Now when my tabs exceeded than the available width, the side menu button is displayed. On click of that button, the menu is displayed, but the graphic(s) in all the tabs are disappeared.

      This is because of the following code in clone() method in TabPaneSkin:

      if (paramNode instanceof Label) {
      localObject1 = (Label) paramNode;
      localObject2 = new Label(((Label) localObject1).getText(), ((Label) localObject1).getGraphic());
      return localObject2;
      }

      If you notice, instead of cloning the graphic, the graphic is copied from one location to another.

      You can find the sample demo below:

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.control.Tab;
      import javafx.scene.control.TabBuilder;
      import javafx.scene.control.TabPane;
      import javafx.scene.control.TabPaneBuilder;
      import javafx.stage.Stage;

      public class TestTabPane extends Application {

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

      @Override
      public void start(Stage paramStage) throws Exception {
      TabPane tabPane = TabPaneBuilder.create().build();
      for (int i = 1; i <= 10; i++) {
      tabPane.getTabs().add(buildTab("tab" + i));
      }
      Scene scene = new Scene(tabPane, 300, 275);
      paramStage.setScene(scene);
      paramStage.show();
      }

      public Tab buildTab(String name) {
      final Tab tab = TabBuilder.create().closable(false).build();
      Label label = new Label();
      // for following line i am setting Label(Node) as grapics.
      // this will not get clonned in TabPaneSkin
      label.setGraphic(new Label(name));
      tab.setGraphic(label);
      return tab;
      }
      }

            jgiles Jonathan Giles
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: