Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing fonts in JLabel?  RSS feed

 
David Triple
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So i cant get this to cahnge the font, it always stays the same.. Any ideas?
 
Ronald Castillo
Ranch Hand
Posts: 47
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the setFont method on the JLabel class.
top.add(new JLabel("Welcome to the HI Lo Game!").setFont(new Font("Papyrus", Font.BOLD, 60)));
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That doesn't compile as setFont is a void method. You probably meant something like:
 
David Triple
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'void' type not allowed here


when i did that it gave me this exception
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So use Wouter's code; that solves that problem.
 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like a GUI-related question, so to the GUI forum it shall go!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!