繁体   English   中英

Jtable中的JComboBox不会在单击鼠标时停止编辑

[英]JComboBox in Jtable doesn't stop editing on mouse click

我有一个10行2列的Jtable

第nb 2列是可编辑的JCombobox

当我在JCombobox手动输入一些值时,当我按JCombobox时,该值将保持JCombobox

但是,当我在JCombobox放置一些值并用鼠标单击到其他单元格时,该值将分配给该单元格而不是我实际上正在编辑的单元格。

基本上,当该单元格失去焦点时,它不会停止编辑该单元格。

当我单击下一个单元格并将新值分配给该单元格时,它将停止编辑。

有什么建议么?

您应该在JCombobox组件上添加焦点侦听器,并且由于焦点丢失,您应该停止在表格单元格编辑器中进行编辑。 例如:

public class TestTableCellEditor extends DefaultCellEditor 
                                      implements FocusListener {
private JComboBox comboBox;

public TestTableCellEditor(JComboBox comboBox) {
   this.comboBox = comboBox;
   comboBox.addFocusListener(this);       
}
// ... Some other things in the editor

public void focusGained(FocusEvent e) {
// You don't need to do anything here
}
public void focusLost(FocusEvent e) {        
    stopCellEditing();        
}
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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