Dynamic Panels

I am adding panels dynamically to a main Panel. But the panels are not getting automatically displayed as and when they are created and added to the main panel. How to make this?Any ideas?
[202 byte] By [Er.Vela] at [2007-11-26 18:47:50]
# 1
Not really sure what your problem is (please try posting come code between the code tags) ... but you might have to repaint() the panel for them to show, possibly.
JJCoolBa at 2007-7-9 6:21:47 > top of Java-index,Java Essentials,New To Java...
# 2

private void btnAddForm_actionPerformed(){

JPanel newFormPanel=new JPanel();

JTextField formType = new JTextField("formType");

JFormattedTextField startDate = new JFormattedTextField("yyyy/mm/dd");

JFormattedTextField endDate = new JFormattedTextField("yyyy/mm/dd");

JRadioButton reqdIK = new JRadioButton();

JCheckBox chkDel = new JCheckBox();chkDel.setName("del");

newFormPanel.setLayout(new GridLayout(1,5));

newFormPanel.add(formType);newFormPanel.add(startDate);newFormPanel.add(endDate);

newFormPanel.add(reqdIK);newFormPanel.add(chkDel);newFormPanel.setVisible(true);

pnlFprmInput.add(newFormPanel);

scrollForms.getRootPane().paintImmediately(0,0,(int)pnlFprmInput.getSize().getWidth(),(int)pnlFprmInput.getSize().getHeight());

scrollForms.repaint();

dateAValidation(startDate,endDate);

dateBValidation(endDate,startDate);

}

I tried many things like paint , repaint, paintImmediately.

Er.Vela at 2007-7-9 6:21:47 > top of Java-index,Java Essentials,New To Java...
# 3
here scrollForms is JScrollPane(newFormPanel)scrollForms is adde dto some other main panel
Er.Vela at 2007-7-9 6:21:47 > top of Java-index,Java Essentials,New To Java...
# 4

This is Java. It is the second best programming language, next to C++. It trades convenience for power. Putting a method with _actionPerformed() does not magically add an action listener to the object.

You have to call addActionListener(this) to btnAddForm.

The method also must be public.

It accepts an argument of ActionEvent.

public void actionPerformed(ActionEvent e) {}

Finally, the class must implement ActionListener.

Lord_Jirachia at 2007-7-9 6:21:47 > top of Java-index,Java Essentials,New To Java...
# 5

No, My friend. it s not actually like u feel.

it is like

button.addActionListener(new ActionListener(){

public void actionPerformed(){

button_actionPerformed();

}

})

so action listener will be added.

and the added things are getting displayed when the scrreen is resized.

But, i need them to be displayed as and when they are added.

Any Ideas?

Er.Vela at 2007-7-9 6:21:48 > top of Java-index,Java Essentials,New To Java...
# 6
if pnlFprmInput is the panel you're having problems with, then add these 2 linespnlFprmInput.add(newFormPanel);pnlFprmInput.revalidate();//<pnlFprmInput.repaint();//<sometimes not required
Michael_Dunna at 2007-7-9 6:21:48 > top of Java-index,Java Essentials,New To Java...