user2022068
user2022068

Reputation:

JavaFx: tab rounded corners

To make my tab corners rounded I use the following code:

.tab {
    -fx-border-radius: 10 10 0 0;
    -fx-background-radius: 10 10 0 0;
}

.tab:selected .focus-indicator {
    -fx-border-radius: 10 10 0 0, 10 10 0 0;
}

However, I get rather strange behaviour. When new tab is created it has some extra corners which later disappear when I change focus or create new tab. For example - I create the first tab. enter image description here

Now I create the second tab. The first tab is already normal, but the second has this strange corners. enter image description here

I've checked on centos and win7 - behaviour is the same. How to fix it?

EDIT 1
This is all my css file. The final target to make tab headers bigger with rounded corners.

.tab:selected .focus-indicator {
    -fx-border-radius: 10 10 0 0, 10 10 0 0;
     -fx-border-insets: -7 -7 -9 -8, -5 -5 -9 -6;
}

.tab-pane > .tab-header-area > .headers-region > .tab:selected{
    -fx-border-insets: 10 10 10 10, 10 10 10 10;
}

.tab-pane > .tab-header-area > .headers-region > .tab > .tab-container > 
.tab-label {
    -fx-alignment: CENTER;
    -fx-text-fill: -fx-text-base-color;
    -fx-padding:0 10 0 0;
}

.tab-header-area .tab{
    -fx-padding:4 10 5 10;
    -fx-border-radius: 10 10 0 0;
    -fx-background-radius: 10 10 0 0;
}

EDIT 2
I've checked it on two different PC: 1(Ubuntu),2(Centoc 71 and VM Win7). I tried to compile with oracle jdk - result is the same.

Upvotes: 5

Views: 4944

Answers (3)

Elltz
Elltz

Reputation: 10859

It is CornerRadii , it just increases & decreases

Upvotes: 0

aw-think
aw-think

Reputation: 4803

This is an already reported bug https://javafx-jira.kenai.com/browse/RT-40462

UPDATE The bug has moved to the openjdk bugtracking system:

https://bugs.openjdk.java.net/browse/JDK-8090243

Some of your code was redundant. So this should work.

.tab:selected .focus-indicator {
    -fx-border-radius: 10 10 0 0, 10 10 0 0;
    -fx-border-insets: -6 -9 -8 -8, -5 -8 -7 -7;
}
/*
.tab-pane > .tab-header-area > .headers-region > .tab:selected{
    -fx-border-insets: 0 1 1 0, 1 2 0 1, 2 3 0 2;
}
*/
.tab-pane > .tab-header-area > .headers-region > .tab > .tab-container > .tab-label {
    -fx-padding:0 10 0 0;
}

.tab-header-area .tab{
    -fx-padding:4 10 5 10;
    -fx-background-radius: 10 10 0 0;
}

This will look like that:

enter image description here

UPDATE

But if you really only want to have more radius to the rounded corners, this is all you have to do:

.tab-pane > .tab-header-area > .headers-region > .tab {
    /* if outer border should be 10 radius */
    -fx-background-radius: 10 10 0 0, 9 9 0 0, 8 8 0 0;
}

.tab-pane:focused > .tab-header-area > .headers-region > .tab:selected .focus-indicator {
    -fx-border-radius: 9 9 0 0, 8 8 0 0;
}

UPDATE

This is what I get from your code. There is a strange behaviour when adding a newly created tab. So I made a gif to show how the mouseover is working.

enter image description here

UPDATE

Upvotes: 3

varren
varren

Reputation: 14731

So lets suppose that it's a bug, and you css is fine, the only solution i see for now is to remove and add default styles after some delay. Something like this:

 Tab tab = new Tab("Tab " + (tabs.getTabs().size() + 1));
 tabs.getTabs().add(tab);
 new Thread(()-> {
     try {
         Thread.sleep(50);
     } catch (InterruptedException e) {
         e.printStackTrace();
     }
     Platform.runLater(()->{
           tabs.getStyleClass().remove("tab-pane");
           tabs.getStyleClass().add("tab-pane");
     });
 }).start();

Nasty hack to be honest, but it works for me:enter image description here

Upvotes: 2

Related Questions