Simply Adding 200 buttons to a jframe fails.

Hi every one..

the aim of this code is simply to open a new frame and add 200 buttons to a scrollable pane in it.. it has no compile error. But sometimes the frame appears blank. Does swing not able to add 200 buttons? (some time 2000 buttons etc. may be needed in a frame)

or there is a methodic error..Thanx !!

JFrame fr=new JFrame("new window");

fr.setSize(1024,738);

fr.setLocation(0,0);

fr.setLayout(null);

fr.setVisible(true);

Container f_con= fr.getContentPane();

f_con.setLayout(null);

JPanel list =new JPanel();//> 200 buttons will be in this panel

list.setLayout(null);

list.setSize(1015,650);

for(int i=0;i<200;i++){//> buttons attached to the list Panel

JButton newbut=new JButton("butyon>"+i);

newbut.setSize(99,29);

newbut.setLocation(1,i*50);

list.add(newbut);

list.setPreferredSize(new java.awt.Dimension(997,i*50));

}

JScrollPane mainpanel=new JScrollPane(list);//>scrollable panel that //contains list panel..

mainpanel.setSize(1015,650);

mainpanel.setLocation(5,50);

f_con.add(mainpanel);//add the main panel to the frame container pane

[1852 byte] By [serdarKa] at [2007-11-26 18:53:40]
# 1
Move the fr.setVisible(true) line to the end, after you add all the components.Or else you need to call revalidate on the content pane after adding the new components:((JComponent) f_con).revalidate();
Rodney_McKaya at 2007-7-9 6:27:41 > top of Java-index,Desktop,Core GUI APIs...
# 2
Try to analyze your code!always put setVisible() method at the last part of the program!
henyoa at 2007-7-9 6:27:41 > top of Java-index,Desktop,Core GUI APIs...
# 3

> Try to analyze your code!

> always put setVisible() method at the last part of the program!

This is not a must.

You can add components after the frame is visible, you just need to call revalidate.

And check the other answers before you post, no need to repeat what was already said, or suggest something after the [url http://forum.java.sun.com/thread.jspa?threadID=5138414]problem[/url] was already resolved...

Rodney_McKaya at 2007-7-9 6:27:41 > top of Java-index,Desktop,Core GUI APIs...
# 4
Thannks very much for your answer. It seems and reasonable way to revalidate or set visible at the end. And I have tryed them, unfortunaltely my problem was not solved :(it may have decreased the fail probability, but some times it still seems empty.
serdarKa at 2007-7-9 6:27:41 > top of Java-index,Desktop,Core GUI APIs...
# 5

Solved by revalidate !! :) Even 10.000 buttons etc. added succesfully..

I have had missplaced revalidate (before adding list) on my previous thread..

(as an information for future readers, this kind of problem not solved by making visible at the end,I've tried it. But REVALIDATEing as it is written above, after adding all to f_win solves the problem)

serdarKa at 2007-7-9 6:27:41 > top of Java-index,Desktop,Core GUI APIs...