How to write JavaFX CSS for tab pane


We are writing code for this result 

JavaFX CSS for TabPane

  
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.
 
JavaFx TabPane CSS


Then clear all text from tabs in tab pane.

JavaFx TabPane CSS

Create CSS file on your computer/laptop and add CSS file in your tab pane.

JavaFx TabPane CSS



Now download icons you want to add in your tab pane. Already downloaded ;)

JavaFx TabPane CSS

  

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
}

JavaFx TabPane CSS


Now add ImageView in each tab.

JavaFx TabPane CSS


Add fx: id to all ImageView in SceneBuilder.

JavaFx TabPane CSS

   

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");
}


JavaFx TabPane CSS



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;   
}


JavaFx TabPane CSS



Add fx:id to tabs in tab pane.

JavaFx TabPane CSS


 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;
}


JavaFx TabPane CSS


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;
   
}


JavaFx TabPane CSS



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");
    }


JavaFx TabPane CSS


And we did CSS code ;)


- Happy Coding

Comments

Popular posts from this blog

How to add JavaFX CSS in your SceneBuilder

Basic of JavaFX CSS Syntax