Reputation: 336
i am creating a software for my project and here is what i have done so far.. what i am trying to do is, i have a jpane witch is created using net beans and it is inside a scrollpane(witch is also add using netbeans) and dynamically i created set of jpanes and add those jpanes in to the jpane i created using netbean.now the scrollpane doesn't work..i cant figure out the reason please help me
this is what i did
int size=(int)jSpinner1.getValue();
a=new JPanel [size];
nameoftext=new JLabel[size];
name=new JTextField[size];
but =new JButton[size];
iamge=new JLabel[size];
jPanel1.removeAll();
for(int x=0;x<size;x++)
{
a[x]=new JPanel(new FlowLayout());
jPanel1.setLayout(new BoxLayout(jPanel1,BoxLayout.PAGE_AXIS));//this is the jpanel i created using netbeans
jPanel1.add(a[x]);
a[x].setVisible(true);
}
for(int x=0;x<size;x++)
{
nameoftext[x]=new JLabel("enter name");
nameoftext[x].setText("enter name");
name[x]=new JTextField();
name[x].setName("name"+String.valueOf(x));
name[x].setColumns(20);
a[x].add(nameoftext[x]).setVisible(true);
a[x].add(name[x]).setVisible(true);
}
and there is one more thing i have to drag the border of jframe to make these components visible.. how to add them instantly to the jframe without dragging the frame
Upvotes: 1
Views: 276
Reputation: 324128
When you add (or remove) components from a visible GUI you need to revalidate() the panel to invoke the layout manager so components can be given a proper size (and location), otherwise the size is (0, 0) and there is nothing to paint.
The basic code would be:
panel.add(...);
panel.revalidate();
panel.repaint();
Upvotes: 2