adding and removing items to a JPanel with BorderLayout
810185Nov 3 2010 — edited Nov 3 2010I have a JPanel and have set the layout manager to "BorderLayout".
I add a JMenu using "theJPanel.add(firstJMenu,BorderLayout.NORTH);"
and another JPanel using "theJPanel.add(subJPanel,BorderLayout.CENTER);"
Then, I want to change the contents of the two positions. I do
theJPanel.removeAll();
theJPanel.add(newJMenu,BorderLayout.NORTH);
theJPanel.add(newJPanel,BorderLayout.CENTER);
theJPanel.validate();
Things MOSTLY work great but, occasionally, I get a exception during repaint "IndexOutOfRange" and "no child 1".
It appears that the 'remove' is not synchronized with the repaint walking the component subelements. I use eclipse and walk through the remove and things appear synchronized........
I would have expected this to be a common programming style. Is this just a wrong headed approach?
How can I have the same effect?
My thanks,