java - How to link two Jlist with a MouseClick event -


in code i'm creating jlist , b , i'm trying construct jlist depending on user click( or b ). if user clicks want list2 appear in frame. if clicks b list3 must appear. right have click frame in order list appear. can explain me how possible , what's wrong code?

import java.awt.*;        import java.awt.event.*;  import javax.swing.*;    public class test extends jframe implements mouselistener {     private static jlist list1 = new jlist();     private static jlist list2 = new jlist();     private static jlist list3 = new jlist();     private static jpanel jp1;     private static jscrollpane listscroller2,listscroller3;     private defaultlistmodel listmodel1,listmodel2,listmodel3;      public test()      {     settitle("menu");     jtabbedpane jtp = new jtabbedpane();     setsize(600,600);     getcontentpane().add(jtp);     jp1 = new jpanel();      jp1.setlayout(new borderlayout());       listmodel1 = new defaultlistmodel();     listmodel1.addelement("a");     listmodel1.addelement("b");      list1 = new jlist(listmodel1);     jscrollpane listscroller1 = new jscrollpane(list1);      listscroller1.setpreferredsize(new dimension(100, 100));       jp1.add(listscroller1, borderlayout.west);      listmodel2 = new defaultlistmodel();     listmodel2.addelement("a1");     listmodel2.addelement("a2");       list2 = new jlist(listmodel2);     listscroller2 = new jscrollpane(list2);      listscroller2.setpreferredsize(new dimension(100,100));         listmodel3 = new defaultlistmodel();     listmodel3.addelement("b1");     listmodel3.addelement("b2");       list3 = new jlist(listmodel3);     listscroller3 = new jscrollpane(list3);      listscroller3.setpreferredsize(new dimension(100,100));         jtp.addtab("letters", jp1);      list1.addmouselistener(this);      }      public void mouseclicked(mouseevent e)      {         int = list1.getselectedindex();         if(i == 0)         {             jp1.add(listscroller2, borderlayout.center);          }         else if ( == 1 )         {             jp1.add(listscroller3, borderlayout.center);          }     }  public void mouseexited(mouseevent event){} public void mouseentered(mouseevent event){} public void mousereleased(mouseevent event){} public void mousepressed(mouseevent event){}        public static void main(string[] args)       {         test tp = new test();         tp.setdefaultcloseoperation(jframe.exit_on_close);         tp.setvisible(true);       } } 

edit: , how switch through lists time , not staying in list2 or list3?


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -