jtable中如果某列是自定义的编辑器和绘制器,那么单击这列时,jtable并不会获得焦点,这是为什么? 我定义了一个焦点监听器,加在jtable上时,如果单击自定义的编辑器和绘制器的列,并不会触发相应的事件,这是为什么?我现在只能手动在编辑器里面的每个单选按钮的点击事件中,手动调用jtable的requestFocus才行,非常麻烦 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 相对应 Editor 的代码贴出来.... class TCellEditor extends AbstractCellEditor implements TableCellEditor{ private String mValue; private JPanel panel; private ButtonGroup group; private DefaultTableModel model; public TCellEditor(DefaultTableModel model){ this.model=model; } public void cancelCellEditing() { super.cancelCellEditing(); } public Object getCellEditorValue() { return group.getSelection().getActionCommand(); } public boolean shouldSelectCell(EventObject anEvent) { return true; } public boolean stopCellEditing() { super.stopCellEditing(); return true; } public boolean isCellEditable(EventObject e) { return true; } public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { panel=new JPanel(); group=new ButtonGroup(); final JTable t=table; ActionListener action=new ActionListener(){ public void actionPerformed(ActionEvent e) { t.requestFocus(); } }; JRadioButton radio1=new JRadioButton("命令1"); JRadioButton radio2=new JRadioButton("命令2"); JRadioButton radio3=new JRadioButton("命令3"); group.add(radio1); group.add(radio2); group.add(radio3); String vlu=(String)value; TableModel model=t.getModel(); radio1.setActionCommand("1"); radio2.setActionCommand("2"); radio3.setActionCommand("3"); radio1.addActionListener(action); radio2.addActionListener(action); radio3.addActionListener(action); panel.add(radio1); panel.add(radio2); panel.add(radio3); radio1.setSelected("1".equals(vlu)?true:false); radio2.setSelected("2".equals(vlu)?true:false); radio3.setSelected("3".equals(vlu)?true:false); return panel; }} 当编辑的时候,焦点自然会在编辑器(JTextField)上。 JTable默认的是用JLabel显示表格,并且在绘制器定义了许多方法,自定义的通常没写周全的话会少一些方法 to yonghar: 但既然单元格都获得焦点了,jtable还不获得焦点吗?如果用默认的编辑器,单元格是文本框的编辑器,那么它获得焦点,jtable也有焦点了。 ireport总是多出一个空白页 各位大侠,如何用JXL设置EXCEL单元格的边框线和宽度呢? 请问java中有没有一种方法直接判断日期是否为合法的? 字符判断 弄了一晚上的Scrollable接口问题,还没有解决,求大侠帮忙!!急 做一个jtable, 如何做到 使行高随鼠标托动变化?谢谢 关于Myeclipse问题(初级) 如何设置文本区域的字体字号???(用Font可以吗) 大家来看看这篇文章,有做市场的必看,题材大大的丰富。 为什么这个包找不到? 谁了解新IO的有关知识,看得乱七八糟的,Selector等等 一个根据字符串生成xml树的问题!!
private String mValue;
private JPanel panel;
private ButtonGroup group;
private DefaultTableModel model;
public TCellEditor(DefaultTableModel model){
this.model=model;
}
public void cancelCellEditing() {
super.cancelCellEditing();
} public Object getCellEditorValue() {
return group.getSelection().getActionCommand();
} public boolean shouldSelectCell(EventObject anEvent) {
return true;
} public boolean stopCellEditing() {
super.stopCellEditing();
return true;
}
public boolean isCellEditable(EventObject e) {
return true;
} public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
panel=new JPanel();
group=new ButtonGroup();
final JTable t=table;
ActionListener action=new ActionListener(){ public void actionPerformed(ActionEvent e) {
t.requestFocus();
}
};
JRadioButton radio1=new JRadioButton("命令1");
JRadioButton radio2=new JRadioButton("命令2");
JRadioButton radio3=new JRadioButton("命令3");
group.add(radio1);
group.add(radio2);
group.add(radio3);
String vlu=(String)value;
TableModel model=t.getModel();
radio1.setActionCommand("1");
radio2.setActionCommand("2");
radio3.setActionCommand("3");
radio1.addActionListener(action);
radio2.addActionListener(action);
radio3.addActionListener(action);
panel.add(radio1);
panel.add(radio2);
panel.add(radio3);
radio1.setSelected("1".equals(vlu)?true:false);
radio2.setSelected("2".equals(vlu)?true:false);
radio3.setSelected("3".equals(vlu)?true:false);
return panel;
}
}
但既然单元格都获得焦点了,jtable还不获得焦点吗?如果用默认的编辑器,单元格是文本框的编辑器,那么它获得焦点,jtable也有焦点了。