How to write JavaFX CSS for tab pane
We are writing code for this result
First, we have to change our side of tab pane so just select tab pane and change side of tab pane as shown in the figure.
Then clear all text from tabs in tab pane.
Create CSS file on your computer/laptop and add CSS file in your tab pane.
Now download icons you want to add in your tab pane. Already downloaded ;)
Let’s add CSS syntax for tab pane. Set height and width of tabs using width and height syntax.
.tab-pane {
-fx-tab-min-height: 9em;
-fx-tab-max-height: 9em;
-fx-tab-min-width: 4em;
-fx-tab-max-width: 4em;
-fx-padding: 0 -1 -1 0
}
Now add ImageView in each tab.
Add fx: id to all ImageView in SceneBuilder.
Add images (icons for tabs) you downloaded in tabs using CSS syntax.
Note : store all images in your CSS folder.
#img1{
-fx-image: url("img001.png");
}
#img2{
-fx-image: url("img002.png");
}
#img3{
-fx-image: url("img003.png");
}
#img4{
-fx-image: url("img004.png");
}
Clear header are from tab pane
.tab-pane:left *.tab-header-area
{
-fx-background-insets: 0, 0 0 10;
-fx-padding: 0.0em 0.0em 0.0em 0.0em;
}
Add fx:id to tabs in tab pane.
Change the background color of tabs and add some padding to tabs.
.tab{
-fx-background-color: #FFFFFF;
-fx-background-insets: 0.0;
-fx-background-radius: 0.0;
-fx-padding: 0 10 0 10;
}
Add CSS code when tabs selected example when I will select message tab then message tab background color change and add the light border at the right side.
.tab:selected
{
-fx-background-color: #F2FEFA;
-fx-background-radius: 0;
-fx-background-insets: 0;
-fx-border-width: 0 0 5 0;
-fx-border-color: #05D39B;
}
Now at last we also want to change color of icons when user will select particular tab.
#customer:selected * {
-fx-image: url("img01.png");
}
#profile:selected *{
-fx-image: url("img02.png");
}
#message:selected *{
-fx-image: url("img03.png"); }
#feedback:selected * {
-fx-image: url("img04.png");
}
And we did CSS code ;)
- Happy Coding
Comments
Post a Comment