I'm trying to develop a GUI for a web application and I wanted to set a TabPane with tabs placed at left keeping the tab headers horizontal. I already found how to place the tabs at left, but after many searches I didn't succeed to set the headers in the right alignment. They still vertical and difficult to read.
How could I fixed that?
You can use CSS to customize the tabs and tab labels:
.tab *.tab-label {
-fx-rotate: 90;
}
.tab {
-fx-padding: 3em 0.5em 3em 0.5em;
}
Add this method in you code and pass your tabPane to it:
void setTabPaneLeftTabsHorizontal(TabPane tabPane){
tabPane.setSide(Side.LEFT);
tabPane.setRotateGraphic(true);
Label l = null;
StackPane stp = null;
for(Tab t : tabPane.getTabs()){
l = new Label(t.getText());
l.setRotate(90);
stp = new StackPane(new Group(l));
stp.setRotate(90);
t.setGraphic(stp);
t.setText("");
}
tabPane.setTabMinHeight(100);
tabPane.setTabMaxHeight(100);
}
There is an open feature request for this: RT-19547 New API to rotate text on tabpane tabs
The feature request is currently open, but not scheduled for implementation. You can vote for or comment on the feature request and link back to this StackOverflow post to register your interest in the feature.
To implement this yourself, you will need to create a new TabPane skin or patch the existing TabPane skin, which is likely not trivial.
You may use the following method to create the tab header
private StackPane createTabHeader(String text, Node graphics){
return new StackPane(new Group(new Label(text, graphics)));
}
Then call it in your code like the following:
Tab tab = new Tab();
tab.setGraphic(createTabHeader("TEXT", new ImageView("IMAGE_PATH")));
Note that you need to set the width and height of the tabs as they will not scale automatically.
TabPane tabPane = new TabPane(tab);
tabPane.setSide(Side.LEFT);
tabPane.setTabMinWidth(50);
tabPane.setTabMaxWidth(50);
tabPane.setTabMinHeight(200);
tabPane.setTabMaxHeight(200);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With