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

Tree item graphics overlaps text.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8
    • Fix Version/s: 8
    • Component/s: javafx
    • Environment:

      jdk1.8.0b86

      Description


      To reproduce:
      Click 'Initialize';
      Click 'Set graphic';

      import com.sun.javafx.runtime.VersionInfo;
      import javafx.application.Application;
      import static javafx.application.Application.launch;
      import javafx.application.Platform;
      import javafx.beans.property.SimpleIntegerProperty;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.beans.value.ObservableValue;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.SelectionMode;
      import javafx.scene.control.TreeItem;
      import javafx.scene.control.TreeTableColumn;
      import javafx.scene.control.TreeTableColumn.CellDataFeatures;
      import javafx.scene.control.TreeTableView;
      import javafx.scene.control.cell.ChoiceBoxTreeTableCell;
      import javafx.scene.control.cell.TextFieldTreeTableCell;
      import javafx.scene.input.MouseButton;
      import javafx.scene.input.MouseEvent;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.Pane;
      import javafx.scene.paint.Color;
      import javafx.scene.shape.Circle;
      import javafx.stage.Stage;
      import javafx.util.Callback;

      public class Main extends Application {
          
          private SimpleIntegerProperty clickCounter = new SimpleIntegerProperty(0);
          private ObservableList<String> idPool = FXCollections.observableArrayList();
          private TreeTableView ttv;
          Pane root;
          
          @Override
          public void start(Stage primaryStage) {
              Button btnInit = new Button("Initialize");
              btnInit.setOnAction(new EventHandler<ActionEvent>() {

                  @Override
                  public void handle(ActionEvent t) {
                      initTreeTableView();
                  }
              });
              Button btnSetGraphic = new Button("Set graphic");
              btnSetGraphic.setOnAction(new EventHandler<ActionEvent>() {

                  @Override
                  public void handle(ActionEvent event) {
                      TreeItem parent = ttv.getRoot();
                      Circle circle = new Circle(6.75, Color.RED);
                      
                      ((TreeItem) parent.getChildren().get(0)).setGraphic(circle);
                  }
              });
              
              root = new HBox(10.0);
              root.getChildren().addAll(btnInit, btnSetGraphic);
              Scene scene = new Scene(root, 400, 300);
              
              primaryStage.setTitle(VersionInfo.getRuntimeVersion());
              primaryStage.setScene(scene);
              primaryStage.show();
          }

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

          private void initTreeTableView() {
              ttv = new TreeTableView();
              root.getChildren().add(ttv);
              
              ttv.setRoot(new TreeItem(new Main.Data("Root", "42")));
              ttv.getRoot().setExpanded(true);
              
              final TreeTableColumn colName = new TreeTableColumn("Name");
              colName.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<Main.Data, String>, ObservableValue<String>>() {
                  @Override
                  public ObservableValue<String> call(CellDataFeatures<Main.Data, String> p) {
                      return p.getValue().getValue().name;
                  }
              });
              
              colName.setMinWidth(100d);
              
              final TreeTableColumn colId = new TreeTableColumn("Id");
              colId.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<Main.Data, String>, ObservableValue<String>>() {
                  @Override
                  public ObservableValue<String> call(CellDataFeatures<Main.Data, String> p) {
                      return p.getValue().getValue().id;
                  }
              });
              
              colId.setMinWidth(75d);
              
              ttv.getColumns().addAll(colName, colId);

              ttv.setOnMouseClicked(new EventHandler<MouseEvent>() {
                  @Override
                  public void handle(MouseEvent t) {
                      if (t.getButton() == MouseButton.PRIMARY) {
                          clickCounter.set(clickCounter.get() + 1);
                      }
                  }
              });

              ttv.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
              ttv.getSelectionModel().setCellSelectionEnabled(true);
              ttv.setEditable(true);
              colName.setCellFactory(TextFieldTreeTableCell.forTreeTableColumn());
              colId.setCellFactory(ChoiceBoxTreeTableCell.forTreeTableColumn(idPool));
              
              Platform.runLater(new Runnable() {
                  @Override
                  public void run() {
                      for (int i = 0; i < 10; i++) {
                          String id = "id - " + i;
                          idPool.add(id);

                          TreeItem treeItem = new TreeItem(new Main.Data("item - " + i, id));
                          ttv.getRoot().getChildren().add(treeItem);

                          for (int j = 0; j < 2; j++) {
                              treeItem.getChildren().add(new TreeItem(new Main.Data("item - " + i + " - " + j, id)));
                          }
                      }
                  }
              });
          }
          
          private class Data {
              public SimpleStringProperty name;
              public SimpleStringProperty id;
              
              public Data(String _name, String _id) {
                  name = new SimpleStringProperty(_name);
                  id = new SimpleStringProperty(_id);
              }
          }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jgiles Jonathan Giles
              Reporter:
              dzinkevi Dmitry Zinkevich (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Due:
                Created:
                Updated:
                Resolved:
                Imported: