I have some custom components with overriden paintComponent(Graphics g) method. In some components drawString() method from Graphics g object is used.
I want to define custom fonts for such drawn strings.
I have *.ttf files with true type fonts definitions.
I have a css file with style classes, defining fonts like:
.rosTexLogoTitle {
-fx-font: bold 20pt 'Tahoma Bold';
-fx-text-fill: #246db6;
-fx-font-weight: heavybold;
-fx-padding: 0 10 0 0
I want to define all properties from css in my java class or maybe there is a way to use styles directly from css-files(not necessary).
I’ve tried to create font with a constructor with Map parameter:
public Font(Map<? extends Attribute, ?> attributes) {
}
But I didn’t success.
I can create custom font with Font.createFont(style, path) then can derive it to set size. Color can be set in Graphics.setColor(). But I can’t set ‘Tahoma Bold’.
You can’t set the font weight or family; these are just used to select the correct
.ttffile.So the solution is to use the correct
.ttffile to begin with. For example, the font familyArialcomes in four files: