Domanda

If I do Right click on a text box in my JavaFX application the menu items display as bold font. This happens in some text boxes. For example we have one login screen where menu item is displayed properly but in other screen its displaying in bold.

Note: I haven't written any code for right click on text box, as i guess its an internal feature and it displays the usual cut, copy, paste, delete and select all.

How to avoid context menu showing as bold?

This is happening only when I am setting the CSS of label in front of text box as bold.

.label { -fx-font-weight:bold; }

One last thing is that these controls are generated dynamically. Its a popup containing Label, Textbox and a Button.

È stato utile?

Soluzione

By setting

.label { -fx-font-weight:bold; }

and by loading this CSS to scene you are overriding the global default CSS selector for labels defined in caspian.css, and thus changing all font-weight properties to bold of all labels in the scene, the label of context menu as well.
You should define your own CSS selector and apply it for desired labels only :

#my-bold-label {
    -fx-font-weight:bold;
}

in java code:

Label lbl = new Label("My bold text");
lbl.setId("my-bold-label");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top