|
|
Re: Text in a JFrame?
|
Posted: Sep 28, 2005 11:14 PM
|
|
> How do you actually use a JLabel? I tried this and nothing > showed up in my window: > > JLabel label = new JLabel("Text-Only Label"); > label.setFont(new Font("Serif", Font.PLAIN, 36));
You need to add it to the frame and make sure the frame is set as myFrame.setVisible(true);
Here is an example:
JFrame someFrame = new JFrame();
JLabel label = new JLabel("Text-Only Label");
label.setFont(new Font("Serif", Font.PLAIN, 36));
someFrame.add(label);
someFrame.setSize(230, 230);
someFrame.setVisible(true);
or if your class is extending JFrame then it would simply be:
// set Layout to whatever Layout Manager
// flowLayout, GridLayout, etc...
getContentPane().setLayout(new FlowLayout());
JLabel label = new JLabel("Text-Only Label");
label.setFont(new Font("Serif", Font.PLAIN, 36));
getContentPane().add(label);
setSize(230, 230); // or whatever size you want
// Place Frame in middle of Screen
setLocationRelativeTo(null);
setVisible(true);
Good luck, Spike
|
|