Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX 2.0 TabPane : Tabs at left and keep tab header horizontal

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?

like image 642
Baya Avatar asked May 23 '13 07:05

Baya


4 Answers

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;
}
like image 112
noxygenx Avatar answered Oct 13 '22 17:10

noxygenx


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);
}
like image 30
Shriram Prajapat Avatar answered Oct 13 '22 16:10

Shriram Prajapat


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.

like image 6
jewelsea Avatar answered Oct 13 '22 16:10

jewelsea


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);
like image 1
Mohamed Handosa Avatar answered Oct 13 '22 17:10

Mohamed Handosa