Hi all!
I was wondering if there's a way to set a custom font to a Menu and it's children. I can actually do this on the Text object like:
...
import javafx.scene.text.Font;
import javafx.scene.text.Text;
...
@FXML private Text lblAppName, lblLoginFailed;
...
Font myFont = Font.loadFont(getClass().getResourceAsStream("/fonts/TRON.TTF"), 40);
if(myFont != null)
lblAppName.setFont(myFont);
But can't do it on the javafx.scene.control.Menu and javafx.scene.control.MenuItem objects.
I even tried the register font approach, even knowing that javafx.scene.text.Font and java.awt.Font are two different objects and got no success at all. As follows
try
{
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/fonts/Baumans-Regular.ttf")));
}
catch (Exception e)
{
e.printStackTrace();
}
and then tried to use it from my css file:
.menu-bar
{
-fx-background-color: transparent;
-fx-font-family: Baumans;
-fx-font-size: 14px;
-fx-text-fill: #00CCFF;
}
But guess what? It didn't (obviously) work. Since Menu and MenuItem don't have a setFont() method I guess I'm stuck with this. Thanks in advance