Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Universal Font

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know how to change the font for an individual component, but I would like to have one font used for every component in my Swing Application. Can someone tell me how to do this.
Thanks

------------------
Happy Coding,
Gregg Bolinger
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I think I have found out a way to do this. But you have to do it for each component. For example, to make a universal font for a JButton I create a new class called buttonFontSetter and extend JButton then I set my font in that class and call that method instead of JButton to create my buttons.
I would have to do the same for my TextFields, Labels, etc. But it works. Just now I have to go and change all my JButton calls. EEKK! Oh well. Such is the life of a programmer.
Ta Ta

------------------
Happy Coding,
Gregg Bolinger
 
Renee Zhang
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I need one font for several components, I'd like to create a font object. For example:
Font customFont = new Font("Dialog", 0, 14);
//Then set component's font to customeFont
buttonOne.setFont(customeFont);
labelOne.setFont(customeFont);
.....
I don't know if I can override something to change the default font. Does anyone know?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would just like to know what the default font is in Windows so that I can set that as the default so that when I take my App over to Linux, it looks the same. As it is now, the font is spaced and seized different and appears larger.
------------------
Happy Coding,
Gregg Bolinger
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that there is a quarantee that it will look alike. Even with the same font and size.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I was fearing. Thank you for the response.

------------------
Happy Coding,
Gregg Bolinger
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic