I have a node which looks like this:
Using only css, I want the label to overlay its parent border color, so the portion of the border color under the label gets invisible.
Css code I used to make this border:
-fx-border-color: black;
-fx-border-width: 3;
-fx-border-radius: 8;
Additional info:
1 -> It’s possible to achieve the same effect by placing -background-color: white to the label, although in my case it’s not a possibility.
2 -> For performance/arch reasons, it’s not possible to achieve this effect through styled BorderPane or TitledPane nodes as suggested in the commends. Hence the importance of only using CSS or at least the less java code as possible.
2
Answers
This is just a code dump of stuff you can choose to study or ignore. I may or may not provide additional explanation or answer further questions about it.
+1 for @jewelsea approach.
More or less I do also have a similar approach to build the border dynamically using Path (including corner radius). I also have another approach by using
inverse clipping
technique.I included both the approaches in the below demo. You can choose or ignore. But my main intension to provide a direction if someone is interested with this.
titledborder.css
For Simple layouts
Ok, the above approaches may be an overkill for the layouts which doesn’t have a dynamic background (like gradients, images.. etc). For simple layouts, as @Slaw mentioned in the first comment, setting
-fx-background-color: inherit;
on both the parent and label should do the trick.CSS Code: