I've created a TabbedPane and put 3 panels on it. One panel, say subpanel1_A, contains a JList object which shows 2 items--"Label_1", "Label_2". When "Label_1" is selected, a label object will be shown on subpanel1_B. Similarily, when "Label_2" is selected, another label object will be shown on subpanel1_C. The problem is I can dynamically display those objects when a specified item in the List is selected. Followwing is part of my code: ================================ public class Skill_1 extends JApplet{ //Define a JTabbedPane object JTabbedPane tabbedPane=null; //Define JPanel objects JPanel panel1=null; JPanel subpanel1_A = null; JPanel subpanel1_B = null; JPanel subpanel1_C = null; //on subpanel1_B JLabel lblB = null; //on subpanel1_C JLabel lblC = null; JList listPanel1=null; ........ ........ String[] actions={"Label_1", "Label_2"}; listPanel1 = new JList(actions); subpanel1_A.add(listPanel1); .......... listPanel1.addListSelectionListener(new test (this, lblB, lblC)); .......... ..........
class test implements ListSelectionListener{ private Skill_1 myApplet; JLabel lbl1 = null; JLabel lbl2 = null; public test(Skill_1 sk1, JLabel lblB, JLabel lblC) {myApplet=sk1; lbl1=lblB; lbl2=lblC; } public void valueChanged(ListSelectionEvent e){ int s = myApplet.listPanel1.getSelectedIndex(); System.out.println("********s = " + s); if(s==0){ System.out.println("panelB"); myApplet.subpanel1_B.add(lbl1); } else if (s==1){ System.out.println("panelB"); myApplet.subpanel1_C.add(lbl2); } } }//End of valueChanged }//End of test Thank you for your help!!!
Jess Ishasder
Greenhorn
Joined: Feb 19, 2002
Posts: 21
posted
0
Sorry!! I mean I "can't" dynamically display those components on the panels when specified item is selected in the list object