aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes setting font of JLabel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "setting font of JLabel" Watch "setting font of JLabel" New topic
Author

setting font of JLabel

Dale Smirth
Greenhorn

Joined: May 17, 2005
Posts: 14
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

Moving to out Swing/AWT forum.


[Jess in Action][AskingGoodQuestions]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38340
    
  23
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

Joined: May 17, 2005
Posts: 14
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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: May 17, 2005
Posts: 14
Sweet - that did it. I thought I had tried it like that before - I guess not. Good looking out!!!


Regards
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38340
    
  23
It's nice when it works isn't it.

Good thing Michael Dunn noticed what was wrong-I didn't.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setting font of JLabel