Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Tab's Size of TabPane in JavaFX

Can we change the tab's size of TabPane in JavaFX? I am using SceneBuilder but it seems it doesn't offer any customozation of the tab's size

Currently I have something like this

.

What I want is basically the tabs to fill the parent and when it is clicked it will show the other forms like this (I made it with button as only the rough image)

enter image description here

Is it possible to do something like this? Any help is appreciated. Thanks

like image 622
Ihsan Haikal Avatar asked Jun 16 '16 10:06

Ihsan Haikal


2 Answers

As far as I know the width and height of elements are read-only. You can set -fx-pref-width, -fx-pref-height, -fx-max-width, -fx-min-width, -fx-max-height, -fx-min-height ,-fx-border-width and -fx-border-height to adjust the size of Java FX elements.

You can do what you want by using Css:

.tab {

    -fx-pref-width: 250
} 
.tab-header-background {
    -fx-background-color:transparent
}

.tab-pane{
    -fx-padding: 0 -1 -1 -1
}

enter image description here

like image 131
Menai Ala Eddine - Aladdin Avatar answered Sep 28 '22 05:09

Menai Ala Eddine - Aladdin


We can set minimum/maximum width/height for all Tabs on TabPane.

@FXML
TabPane tabPane;

and somewhere:

tabPane.setTabMinWidth(33);
tabPane.setTabMinHeight(33);
tabPane.setTabMaxWidth(69);
tabPane.setTabMaxHeight(69);
like image 22
Ihorko.bk Avatar answered Sep 28 '22 04:09

Ihorko.bk