Dynamically adding elements to JTaskPane and JTaskPaneGroup

Whenever you dynamically - at runtime - add components to a JTaskPaneGroup, it is very important to revalidate it. Suppose I want to add a JTaskPaneGroup to an existing JTaskPaneGroup (nested JTaskPaneGroups):

// when building the application, creates a JTaskPaneGroup
JTaskPaneGroup parent = new JTaskPaneGroup();

// later, triggered by the user action, add another JTaskPaneGroup
JTaskPaneGroup child = new JTaskPaneGroup();
parent.add(child);
// make sure to revalidate the parent JTaskPaneGroup
// otherwise the user interface may not repaint correctly
parent.revalidate();
parent.repaint();

And here is the result:

Try it online with Java WebStart
Download the source code

The same applies if you are adding/removing actions, components: make sure to validate!


 
Copyright © 2004-2006 L2FProd.com