user3440686
user3440686

Reputation: 21

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); 

Upvotes: 1

Views: 1095

Answers (1)

camickr
camickr

Reputation: 324118

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.

Upvotes: 2

Related Questions