tags:

views:

35

answers:

1

which is the best way to add formated string in jframe. Previously I was trying to add jlabel

+1  A: 

If you want to display some text in a window, yes, adding a JLabel to your JFrame is fine.

Just create an instance of the font you want and assign it to the JLabel using setFont.

Here is a code samle (taken from here):

Font font = new Font("Jokerman", Font.PLAIN, 35);
JLabel textLabel = new JLabel(textMessage);
textLabel.setFont(font);
Oded
i also want to update that string after 10 seconds interval
nicky
@nicky: Use a java.util.Timer() and SwingUtilities.invokeLater().
Aaron Digulla
Even more conveniently, a javax.swing.Timer action event handler executes on the event dispatch thread: http://java.sun.com/javase/6/docs/api/javax/swing/Timer.html
trashgod