JTable与复杂的编辑器 [英] JTable with a complex editor

查看:144
本文介绍了JTable与复杂的编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多针对JTable的自定义编辑器,并且很难说可用性,特别是关于使用键盘进行编辑的可用性。

I have many custom editors for a JTable and it's an understatement to say that the usability, particularly in regard to editing with the keyboard, is lacking.

主要原因是我的编辑总是创建一个类似的(虽然通常更复杂)的情况:

The main reason for this is that my editors are always created with a similar (though often more complex) situation to this:

@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
  JPanel container = new JPanel();
  container.setLayout(new BorderLayout());
  container.add(field, BorderLayout.CENTER);
  field.setText((String) value);
  container.add(new JButton("..."), BorderLayout.EAST);
  return container;
}

I.E内部有多个组件的面板。实际的文本编辑器是作为编辑器返回的组件的后代。
因此,抛出问题,从我所知道的,JTable正在关注 getTableCellEditorComponent 方法返回的组件,所以当你按下一个键时单元格突出显示它将焦点和按键传递给面板,认为是编辑器。

无论如何我可以通知JTable真正的编辑器是JTextfield吗?
在正确的组件上添加hacky requestFocusInWindow 是不够的,因为按键不会被传递。

I.E a panel with more than one component inside. The actual text editor is a descendant of the component being returned as the editor. So, rendering issues aside, from what I can tell, the JTable is focusing the component that is returned by the getTableCellEditorComponent method so when you press a key with a cell highlighted it passes focus and the key press to the panel, thinking that's the editor.
Is there anyway I can inform JTable that the "real" editor is the JTextfield? Adding a hacky requestFocusInWindow on the correct component is insufficient as the key press won't get passed on.

推荐答案

查看一些相关文章此处和< a href =http://jroller.com/santhosh/entry/keyboard_handling_in_tablecelleditor =nofollow noreferrer>这里。

另一个关于JTable编辑的好文章

这篇关于JTable与复杂的编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆