简体   繁体   中英

JList with enter key

I have a JList already having 3 elements. Now what I want is if I press the enter key on that element i want to open a new JList with new list of create,alter,view as i mentioned below.. I have tried the below code:

Object l1=master.getSelectedValue();
int key = evt.getKeyCode();
if (key == KeyEvent.VK_ENTER) {
         Object ind = master.getSelectedValue();
     //data.add(master.getSelectedValue());
     //master.setListData(data);
         DefaultListModel listmodel=new DefaultListModel();
         listmodel.addElement("Create");
         listmodel.addElement("View");
         listmodel.addElement("Alter");
           //  String[] data = {"Create","View","Alter"};
             JList list = new JList(listmodel);
              list.setFocusable(true); 

Maybe List Action will help you. You create an Action and then the Action will be invoked when you use the Enter key or a mouse double click. When you design a GUI the user should be able to use either the mouse or the keyboard. This class makes it easy to do this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM