- I have an issue when i try to rotate the label by 270
label.setRotate(270)
. - But label text disappear .
That is the code sample.
LineChart chart = new LineChart(new CategoryAxis(), new NumberAxis()); chart.setLegendVisible(false); /** * Grid pane which contain the charts and vertical label to indicate for the row title */ GridPane root = new GridPane(); root.add(chart, 0, 0); /** * Want to add vertical label to refer to the row title. */ Label label = new Label("Row Title"); label.setRotate(270); // label.setMinWidth(200); root.add(label, 1, 0);
Update
- When i try to
setMinWidth(200)
another issue appear.
The
...
text you are seeing is the default value ofellipsisStringProperty
when the text is truncated due to narrow bounds. Thelabel.setMinWidth(200);
should solve of the issue of disappearance.The problem is that adding a rotation to the label doesn't affect its layout bounds. The label is, as far as layout is concerned, still a horizontal control.
Wrapping it in a
Group
will solve most issues, as the group will take the transform into account. However, things like automatic wrapping of text in the label will no longer function.If text wrapping in a vertical label is also desired, then we need to create our own
VerticalLabel
class that re-uses the complex wrapping calculations done byLabel
while showing it vertically.This feature should really be part of the
Label
class itself to be supported properly, but it is possible to work-around it with a new control.Here is the code: