• Post Reply Bookmark Topic Watch Topic
  • New Topic

Uniform Font for class of swing components

 
Kasi Viswan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

Is there a way to set uniform font for only one class of swing components in a JFrame?
Like Bold font for all Labels in the form.

There is a method to get all child components of a Frame but I don't know how to validate if the child component is a JLabel or a JButton or JTextField and so on to set the required font.

I just want to have a method to set a common font among a class of components.

Please let me know if there is a way.

Thanks
Kasi
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JComponent#setFont(Font font)
JLabel and JButton also supports HTML, so if required you can use that to define the font in the html tags.
You can use the instanceof operator to figure out if the child component is a JLabel or whatever.
 
Rob Camick
Ranch Hand
Posts: 2701
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but I don't know how to validate if the child component is a JLabel or a JButton or JTextField




Or you can use Darryl's Swing Utils. The code would be something like:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!