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

Label wrapped text cuts off unexpectedly with non-default font

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • None
    • 8
    • javafx
    • Windows 7 64-bit, JavaFX 8.0.0-ea-b92

    Description

      Run the included source, and notice that the Text within the red outline is cut off prematurely with an ellipsis. This does not occur with the default font, but it might be just coincidence.

      package hs.mediasystem;

      import java.util.Map;
      import java.util.WeakHashMap;

      import javafx.application.Application;
      import javafx.beans.binding.BooleanExpression;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.beans.property.StringProperty;
      import javafx.collections.ObservableList;
      import javafx.scene.Node;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.control.ListView;
      import javafx.scene.layout.BorderPane;
      import javafx.scene.layout.ColumnConstraints;
      import javafx.scene.layout.GridPane;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.Pane;
      import javafx.scene.layout.Priority;
      import javafx.scene.layout.RowConstraints;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class TextFlowSample extends Application {
        private StringProperty plot = new SimpleStringProperty("When the coach of the France soccer team is killed by a poisoned dart in the stadium in the end of a game, and his expensive and huge ring with the diamond Pink Panther disappears, the ambitious Chief Inspector Dreyfus assigns the worst police inspector Jacques Clouseau to the case.");

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

        @Override
        public void start(Stage stage) throws Exception {
          HBox hbox = new HBox();

          hbox.setStyle(" -fx-font-family: \"Arial\"; -fx-font-size: 16px; -fx-font-weight: normal;");

          BorderPane borderPane = new BorderPane() {{
            setTop(new VBox() {{
              setId("title-area");
            }});

            setCenter(new GridPane() {{
              GridPaneUtil.configure(this, new double[] {60, 40}, new double[] {100});

              setHgap(20);

              add(new VBox() {{
                setId("description-area");
              }}, 0, 0);

              add(new VBox() {{
                setId("title-image-area");
              }}, 1, 0);
            }});

            setBottom(new HBox() {{
              setId("link-area");
            }});
          }};

          add(borderPane, "description-area", 6, createPlotBlock());

          ListView<String> listView = new ListView<>();

          listView.setMinWidth(100);
          listView.getItems().add("Some title");

          hbox.getChildren().addAll(borderPane, listView);

          stage.setScene(new Scene(hbox));

          stage.setWidth(1024);
          stage.setHeight(600);
          stage.show();
        }

        protected Pane createPlotBlock() {
          Node plotField = createPlotField();
          VBox.setVgrow(plotField, Priority.ALWAYS);

          return createTitledBlock("PLOT", plotField, plot.isNotEqualTo(""));
        }

        protected Node createPlotField() {
          return new Label() {{
            getStyleClass().addAll("field", "plot");
            wrapTextProperty().set(true);
            textProperty().bind(plot);
            managedProperty().bind(plot.isNotEqualTo(""));
            visibleProperty().bind(plot.isNotEqualTo(""));
          }};
        }

        protected Pane createTitledBlock(final String title, final Node content, final BooleanExpression visibleCondition) {
          return new VBox() {{
            setFillWidth(true);
            getChildren().add(new Label(title) {{
              getStyleClass().add("header");
            }});
            getChildren().add(content);

            if(visibleCondition != null) {
              managedProperty().bind(visibleCondition);
              visibleProperty().bind(visibleCondition);
            }
            setStyle("-fx-border-color: red; -fx-border-width: 2px");
          }};
        }

        private final Map<Node, Double> orderMap = new WeakHashMap<>();

        public boolean add(Pane mainPane, String areaName, double order, Node node) {
          Pane pane = (Pane)mainPane.lookup("#" + areaName);

          if(pane == null) {
            return false;
          }

          ObservableList<Node> children = pane.getChildren();
          int insertPosition = 0;

          for(; insertPosition < children.size(); insertPosition++) {
            Node child = children.get(insertPosition);

            if(orderMap.get(child) > order) {
              break;
            }
          }

          children.add(insertPosition, node);
          orderMap.put(node, order);

          return true;
        }

        public static class GridPaneUtil {
          public static void configure(GridPane gridPane, double[] columns, double[] rows) {
            for(double column : columns) {
              ColumnConstraints constraints = new ColumnConstraints();

              constraints.setPercentWidth(column);

              gridPane.getColumnConstraints().add(constraints);
            }

            for(double row : rows) {
              RowConstraints constraints = new RowConstraints();

              constraints.setPercentHeight(row);

              gridPane.getRowConstraints().add(constraints);
            }
          }

          public static GridPane create(double[] columns, double[] rows) {
            GridPane gridPane = new GridPane();

            configure(gridPane, columns, rows);

            return gridPane;
          }
        }
      }

      Attachments

        Issue Links

          Activity

            People

              fheidric Felipe Heidrich (Inactive)
              jhendrikx John Hendrikx
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported: