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

Height of cells (with non-standard font size) changes on mouse hover when stage NOT focused

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • 8
    • 8
    • javafx
    • Windows 7

      The height of cells changes (specifically when calling prefHeight on a TreeCell) when the font-size of the cell was changed. This however happens ONLY when the Stage is not focused. Hovering over the unfocused Stage where cells are causes them to be resized by what seems to be 2 pixels. Moving the mouse over the cells you can see them jump a bit (please experiment a bit, it is a bit hard to describe).

      Simply removing the setStyle line solves the bug.

      Here is a fully working program that will display the bug:

      package hs.mediasystem.controls;

      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.control.TreeItem;
      import javafx.scene.control.TreeView;
      import javafx.scene.layout.HBox;
      import javafx.stage.Stage;

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

        @Override
        public void start(Stage stage) throws Exception {
          ObservableList<String> items = FXCollections.observableArrayList("Terminator", "Stargate Atlantis", "Star Wars: The Clone Wars", "Star Trek: Voyager", "Stargate Universe");

          HBox box = new HBox();

          TreeView<String> treeView = new TreeView<>();

          treeView.setStyle(" -fx-font-size: 1.2em;");

          TreeItem<String> treeItem = new TreeItem<>("Root");

          for(String item : items) {
            treeItem.getChildren().add(new TreeItem<>(item));
          }

          treeView.setRoot(treeItem);
          treeView.setShowRoot(false);

          box.getChildren().add(treeView);
          box.getChildren().add(new Label("Select an item, deselect the window, then hover over the items with mouse. Item size changes. Doesn't happen when you donot set the font-size.") {{
            setPrefWidth(100);
            setWrapText(true);
          }});

          Scene scene = new Scene(box);

          stage.setScene(scene);
          stage.show();
        }
      }

            jgiles Jonathan Giles
            jhendrikx John Hendrikx
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: