I have VTreePanel class that extends from CPanel which extends from JPanel. The class has a JSplitPane object that is divided into two area: left & right. The left side contains tree menu selection object. At right side, it contains JTabbedPane object. The VTreePanel class is like this:
public final class VTreePanel extends CPanel
implements ActionListener
{
private JSplitPane centerSplitPane = new JSplitPane();
private JTabbedPane tabbedPane;
...
// GET method for the tabbedPane
public JTabbedPane getTabbedPane() {
return tabbedPane;
}
// Constructor
public VTreePanel(int WindowNo, boolean hasBar, boolean editable)
{
...
tabbedPane = new JTabbedPane();
centerSplitPane.add(treePart, JSplitPane.LEFT);
centerSplitPane.add(tabbedPane, JSplitPane.RIGHT); // Look at this
...
}
}
In constructor, I added the tree selection (treePart) and JTabbedPane object (tabbedPane) into the JSplitPane object (centerSplitPane). I don't add any Tab into the tabbedPane yet. Look at the screenshot below:
http://i45.tinypic.com/2v3j0nl.jpg
Then how do I add the tab when user click one of the menu?
I have AMenu class where it has implemented PropertyChangeListener that fired propertyChange method when user clicked a menu:
public final class AMenu extends CFrame
implements ActionListener, PropertyChangeListener, ChangeListener
{
private VTreePanel treePanel = null; // this is the VTreePanel object
...
public void propertyChange(PropertyChangeEvent e)
{
...
// Here I pass the VTreePanel object as parameter to AMenuStartItem thread object
(new AMenuStartItem(cmd, true, sta, this, treePanel)).start();
}
}
You can see that I have VTreePanel object (treePanel) and I pass the VTreePanel object as parameter to AMenuStartItem thread. The AMenuStartItem contains logic that perform adding Tab in JTabbedPane (remember, JTabbedPane object (tabbedPane) is in the VTreePanel).
Here is the AMenuStartItem thread class:
public class AMenuStartItem extends Thread implements ActionListener
{
private VTreePanel m_vtreePanel;
public AMenuStartItem (int ID, boolean isMenu, String name, AMenu menu, VTreePanel vtreepanel)
{
...
m_vtreePanel = vtreepanel; // save the VTreePanel object
}
// The thread method that executed when thread is started
public void run()
{
...
startWindow(0, cmd);
...
}
private void startWindow(int AD_Workbench_ID, int AD_Window_ID)
{
...
// Here I perform adding new tab
m_vtreePanel.getTabbedPane().addTab(frame.getTitle(), frame.getAPanel());
...
}
}
So, the getTabbedPane() returned the JTabbedPane object and the addTab() method is executed but no tab showed up at all.
Anyone know how to fix this problem?