我的jtable有一个单元编辑器,它是作为defaultcelleditor(jcombobox)类的示例实现的。我尝试了几种不同的方法(为swing组合框添加自动完成支持),但仍然不起作用。
1:
//
JComboBox combo = new JComboBox(new Object[] { "Ester", "Jordi", "Jordina", "Jorge", "Sergi" });
AutoCompleteDecorator.decorate(combo);
DefaultCellEditor cellEditor = new DefaultCellEditor(combo);
TableColumn column = myTable.getColumnModel().getColumn(2);
column.setCellEditor(cellEditor);
//
2:
//
Object[] elements = new Object[] { "Ester", "Jordi", "Jordina", "Jorge", "Sergi" };
JComboBox c = new JComboBox(elements);
c.setEditable(true);
AutoCompleteSupport support = AutoCompleteSupport.install(c, GlazedLists.eventListOf(elements));
support.setSelectsTextOnFocusGain(false);
support.setHidesPopupOnFocusLost(false);
support.setStrict(false);
ComboBoxCellEditor combo = new ComboBoxCellEditor(c);
TableColumn column = myTable.getColumnModel().getColumn(2);
ComboTableCellRenderer renderer = new ComboTableCellRenderer();
column.setCellRenderer(renderer);
column.setCellEditor(combo);
//
三:
//
Object[] elements = new Object[] { "Ester", "Jordi", "Jordina", "Jorge", "Sergi" };
JComboBox comboBox = new JComboBox(elements);
comboBox.setEditable(true);
AutoCompletion ac = new AutoCompletion(comboBox);
ac.setStrict(false);
DefaultCellEditor cellEditor = new DefaultCellEditor(comboBox);
TableColumn column = myTable.getColumnModel().getColumn(2);
column.setCellEditor(cellEditor);
//
我面临的问题是,一旦用户开始在组合框中键入内容,它就会退出编辑模式,从而有效地防止输入任何值。
2条答案
按热度按时间slhcrj9b1#
我最喜欢的自动完成jcombobox/jtextfield没有问题,仍然有第二选择的用途
AutoComplete JTextField
而不是AutoComplete JComboBox
,添加到oraclejtable教程的代码中
ff29svar2#
试试这个