• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setting font of JLabel

 
Dale Smirth
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been racking my brain trying to figure out how to change the font of a JLabel that I have in a JFrame.

Regards.





 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to out Swing/AWT forum.
 
Campbell Ritchie
Sheriff
Posts: 48381
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It appears to me that you have correctly set the font on your JFrame, but I can't see anywhere where you have set the font on the JLabel. Try that.
 
Dale Smirth
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I added this line:




I call myself setting the font for the JLabel component, but I get an error when I compile.

The error says:



Also, the ^ is actually between new and Font - i guess it just didn't paste correctly from the compiler.


Regards
[ June 22, 2006: Message edited by: Dale Smirth ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you're trying to change something outside of a method

move
jlblTotalScore.setFont(new Font("Serif", Font.BOLD, 20 ) );

inside the scoreboard() constructor, and it should work fine
 
Dale Smirth
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sweet - that did it. I thought I had tried it like that before - I guess not. Good looking out!!!


Regards
 
Campbell Ritchie
Sheriff
Posts: 48381
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's nice when it works isn't it.

Good thing Michael Dunn noticed what was wrong-I didn't.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic