if the following is run the system.out message says the size of the label is 0,0 why is this? in my real program what i am wanting to do is have an array of words each separately on JLabels and using a slider I am removing the text of random labels but i want the labels to remain the same size as they were with the text so that spaces will appear. I am using setPrefferedSize just after the label is added to the panel and using the current size (which i believe will do what i want) but the size happens to be 0 for which i cannot figure out why.
thanks
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Frame extends JFrame{
public Frame(){
JPanel panel = new JPanel();
this.add(panel);
JLabel label = new JLabel("some text");
panel.add(label);
System.out.println(label.getSize().toString());
}
public static void main (String[] args){
Frame frame = new Frame();
frame.setVisible (true);
frame.setSize (350,200);
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
}
}