Well, letting the JPanel know about the Tabbed Pane is easy.
Subclass JPanel and name is something like JTabbedPanePanel.
public class JTabbedPanePanel extends JPanel
{
private JTabbedPane aJTabbedPane = null;
public JTabbedPanePanel()
{
super();
}
public void setJTabbedPane(JTabbedPane jTabbedPane)
{
aJTabbedPane = jTabbedPane;
}
}
Then at some point you have to be handling the event from the List Box, via a ListSelectionEvent, right? My guess is that the panel itself is listening for that event and then is handeling the event. Then in this case the panel then knows about the event and knows about JTabbedPane and life is good.
Second example. With components like the JList I always make them Listeners of themselves.
public class ExtendedJList extends JList implements ListSelectionListener
{
// Add all the constructors here... each one calling init()
public ExtendedJList()
{
init();
}
private void init()
{
addListSecionListener(this);
}
// Implement the method from ListSelectionListener
public void valueChanged(ListSelectionEvent e)
{
System.out.println("OVERRIDE THIS BEHAVIOR WITH AN ANONYMOUS INNER CLASS!");
}
}
Then when we add this ExtendedJList to a panel we do the following...
ExtendedJList extendedJList = new ExtendedJList()
{
public void valueChanged(ListSelectionEvent e)
{
// 1. Get the JTabbedPane some how...
// 2. Set the assigned tab number on the tabbed pane.
}
}
So at some point the JTabbedPane has to be known. You could use a sington object for the Main JPanel of your application and then have a setter and getter for your JTabbedPane. All these solutions will work.
BUT, again, i would urge you not do do the behavior of having one event on one JPanel to cause the JTabbedPane to change selected tabs. Have the information from the selection on the JList to appear below the JList. The end user will most likely be happier.