问题描述
我创建了一个扩展 JTextField 的组件, 该组件会在您键入时显示项目列表以进行自动完成。 您可以使用箭头键在列表内移动并按 Enter,或双击列表中的项目以选择它, 并完成 TextField 中的文本。
如果我在 Frame 中使用该组件,它可以完美运行,但是当我在 jdialog 中使用它时,双击列表不起作用。有什么想法吗?
这是代码的摘录
public class CTextField extends JTextField implements FocusListener,DocumentListener,KeyListener {
...
public CTextField () {
...
final Window parent = SwingUtilities.getwindowAncestor(this);
popup = new JWindow(parent);
popup.setType(Window.Type.POPUP);
popup.setFocusableWindowState(false);
popup.setAlwaysOnTop(true);
ListModel model = new ListModel();
list = new JList(model);
list.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent mouseEvent) {
JList list = (JList) mouseEvent.getSource();
if (mouseEvent.getClickCount() == 1) {
int index = list.locationToIndex(mouseEvent.getPoint());
if (index >= 0) {
String value = (String)list.getModel().getElementAt(index);
selectItem(value);
}
}
}
});
...
}
...
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)