Javafx & fxml: how to apply a border to a panel or label in my gui?

I just use fxml and it seems like a really cool idea, except for the fact that it's hard for me to work to work. Presumably, I can lay out my GUI using a good markup language, and I can style elements through CSS. Therefore, I have a shortcut in my GUI, and I would like to have a solid black border around it with a width = 1. It seems like it should be simple - fitting the examples that I see here and there in textbooks, etc. I do the following:

<Label text="sample text" style="-fx-border-width: 1; -fx-border-style: solid;" /> 

But that will not work. Borders are not displayed. In Scene Builder, the Property inspector has a text box labeled β€œStyle”, and I see that the style I applied appears there, but I don’t see the border.

What am I missing?

+6
source share
1 answer

You also need to specify a border color. Add this to the Label tab

 -fx-border-color:black; 

In your case, the sample code would be:

 <Label text="sample text" style=" -fx-border-color:black; -fx-border-width: 1; -fx-border-style: solid;" /> 
+19
source

Source: https://habr.com/ru/post/951772/


All Articles