swing create font

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 .ttf file.

So the solution is to use the correct .ttf file to begin with. For example, the font family Arial comes in four files:

arialbd.ttf - Weight "Bold"
arialbi.ttf - Weight "Bold", Slant "Italic"
ariali.ttf  - Slant "Italic"
arial.ttf   - Plain version

Need Your Help

Unable to call the scale() method in Libgdx for android

android libgdx

I've just started learning Libgdx from today by looking at some of the tutorials and find this framework really good, however, I've bumped in a minor problem. I've set up the fonts with the BitmapF...

Multiple User Permissions for other Entities

c# sql-server-2008 asp.net-membership subsonic

Our company is having a problem migrating from a single user application to multiple. Our setup is that a User would own a Product, and that ownership is through a foreign key. Since they owned the

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.