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

TabPane dn't render the graphics properly.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • fx2.0
    • fx2.0
    • javafx
    • windows vista ultimate sp2

      I added the graphics to the Tab and added around 10 to 11 tabs to tabpane. Please see the attached screen shot for more under standing of the bug.
      I have attached the testcase to reproduce the bug.



      ----- Test Case ------

      import javafx.application.Application;
      import javafx.beans.value.ChangeListener;
      import javafx.beans.value.ObservableValue;
      import javafx.geometry.Side;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.control.ChoiceBox;
      import javafx.scene.control.RadioButton;
      import javafx.scene.control.Tab;
      import javafx.scene.control.TabPane;
      import javafx.scene.control.Toggle;
      import javafx.scene.control.ToggleGroup;
      import javafx.scene.image.Image;
      import javafx.scene.image.ImageView;
      import javafx.scene.layout.HBox;
      import javafx.scene.paint.Color;
      import javafx.scene.shape.Rectangle;
      import javafx.stage.Stage;

      /**
       *
       * @author ammulu
       */
      public class TabWithGraphics extends Application {

          TabPane tabPane = null;
          ChoiceBox cb = new ChoiceBox();
          Color colors[] = {Color.BLUE, Color.RED, Color.GREEN, Color.GOLD};

          @Override
          public void start(Stage stage) throws Exception {
              stage.setTitle("Hello World");
              Group root = new Group();
              Scene scene = new Scene(root, 500, 500);

              // create a TabPane instance
              tabPane = new TabPane();
              tabPane.setLayoutX(20);
              tabPane.setLayoutY(20);
              // create individual tabs
              for (int i = 0; i <10; i++) {
                  Tab tab = new Tab();
                  // set the label for tab
                  tab.setText("Tab # " + (i + 1));
                   ImageView imgView = new ImageView();
                   Image img = new Image(TabWithGraphics.class.getResourceAsStream("duke.jpg"));
                   imgView.setImage(img);
                   imgView.setFitHeight(25);
                   imgView.setFitWidth(25);
                   imgView.setPreserveRatio(true);
                   tab.setGraphic(imgView);

                  // add the content to tab
                  tab.setContent(new Rectangle(400, 400, Color.GREEN));

                  // add the tab to TabPane
                  tabPane.getTabs().add(tab);
              }

              // create a hbox to hold the radio buttons
              HBox sideLayout = new HBox();
              sideLayout.setSpacing(10);
              
              final ToggleGroup tg = new ToggleGroup();
              
              RadioButton top = new RadioButton("Top");
              top.setSelected(true);
              top.setUserData("Top");
              top.setToggleGroup(tg);
              
              RadioButton bottom = new RadioButton("Bottom");
              bottom.setToggleGroup(tg);
              bottom.setUserData("Bottom");
              
              RadioButton left = new RadioButton("Left");
              left.setToggleGroup(tg);
              left.setUserData("Left");
              
              RadioButton right = new RadioButton("Right");
              right.setToggleGroup(tg);
              right.setUserData("Right");

              sideLayout.getChildren().addAll(top, bottom, left, right);

              // Add change listener to toggleGroup
              tg.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {

                  public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) {
                      String selectedValue = tg.getSelectedToggle().getUserData().toString();
                      System.out.println(selectedValue);
                      if (selectedValue.equals("Top")) {
                          tabPane.setSide(Side.TOP);
                      }
                      if (selectedValue.equals("Bottom")) {
                          tabPane.setSide(Side.BOTTOM);
                      }
                      if (selectedValue.equals("Left")) {
                          tabPane.setSide(Side.LEFT);
                      }
                      if (selectedValue.equals("Right")) {
                          tabPane.setSide(Side.RIGHT);
                      }
                  }
              });

              root.getChildren().addAll(sideLayout, tabPane);
              stage.setScene(scene);
              stage.setVisible(true);
          }

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


      ----------------------------

        1. Bug.png
          Bug.png
          1021 kB
        2. InitialScreen.png
          InitialScreen.png
          15 kB
        3. duke.jpg
          duke.jpg
          2 kB

            kwwong Kinsley Wong (Inactive)
            lpremkumajfx Lawrence Premkumar (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: