I'd like to make an application in Java with a JList on the left, and then everything else as an area for JPanels. The JPanel that would be displayed to the right of the JList is dependent on which item in the JList is being selected. I want to use a JList as the tabs, in this regard, not JTabbedPane.
How can I set up a listener on my JList that will achieve this?
I tried the following, but it didn't work. I did check that panel1
has both a location (0,0) and a size (greater than (0,0)) after the add
call below.
public void valueChanged(ListSelectionEvent e) {
int i = stepList.getSelectedIndex();
if(i == 0) {
//mainPanel is the green placeholder panel in the image above
mainPanel.add(panel1);
}
}
By the way, I am creating this project in Netbeans.