关于嵌入JTable内JComboBox的事件监听,求各位大牛指教

sha_4yu 2017-02-16 08:43:04
在JTable单元格嵌入JComboBox,在响应鼠标点击事件时,初次点击显示无选中单元格


再次点击却报前次操作坐标值


这让我很 困解,如何实时获得当前点击坐标值呢?
望各位大牛不吝指教,万分感谢
代码附下
		
private JPanel contentPane;
private JTable table;
private JComboBox<String> jcbtest;
private DefaultTableModel tablemodel;

jcbtest=new JComboBox<String>();
jcbtest.addItem("item1");
jcbtest.addItem("item2");
jcbtest.addItem("item3");
jcbtest.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int curi=table.getSelectedRow();
int curj=table.getSelectedColumn();
JOptionPane.showMessageDialog(null, "actionListener:"+curi+" "+curj);

}
});

jcbtest.addItemListener(new ItemListener(){
public void itemStateChanged (ItemEvent e){
int curi=table.getSelectedRow();
int curj=table.getSelectedColumn();
JOptionPane.showMessageDialog(null, "itemstateChanged:"+curi+" "+curj);
}
});

table = new JTable();String title[]={"姓名", "部门", "职位"};
tablemodel=new DefaultTableModel(title, 3);
table = new JTable(tablemodel){
private static final long serialVersionUID=1L;
public boolean isCellEditable( int rowIndex, int columnIndex){
if( rowIndex == getRowCount() - 1 ){
DefaultTableModel dtm=(DefaultTableModel)dataModel;
dtm.addRow(new String[]{"","",""});
}
return true;
}
};
table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(jcbtest));

scrollPane.setViewportView(table);
...全文
301 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
逗泥丸的平方 2017-02-21
  • 打赏
  • 举报
回复
监听table的鼠标事件试试?. addMouseListener 不过为什么你要知道是哪个单元格..
sha_4yu 2017-02-16
  • 打赏
  • 举报
回复

少张图,补上

62,626

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧