[英]JList with enter key
I have a JList
already having 3 elements. 我有一个
JList
已经具有3个元素。 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: 现在我想要的是,如果我按该元素上的回车键,我想打开一个新的
JList
并带有如下所述的create,alter,view的新列表。我已经尝试了以下代码:
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.
创建一个动作,然后在使用Enter键或鼠标双击时将调用该动作。 When you design a GUI the user should be able to use either the mouse or the keyboard.
在设计GUI时,用户应该能够使用鼠标或键盘。 This class makes it easy to do this.
此类很容易做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.