parameterTable.getColumnModel().getColumn(2).setCellEditor(getSubProcessParameterValueCellEditor());parameterTable是你的表格名字 2为第几列getSubProcessParameterValueCellEditor()为得到编辑方式的方法,你可以在这里面定义JButton,不过得让这个JButton继承JFormattedTextField并重写setBounds方法. public void setBounds(int x, int y, int width, int heigth){ super.setBounds(x, y, width, heigth); b_chooser.setBounds(this.getWidth()*3/4, 0, this.getWidth()/4, this.getHeight()); } b_chooser为按扭的定义名称
JTable jTable1 = new JTable(); jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jTable1.addMouseListener(new MouseAdapter(){public void mouseClicked(MouseEvent e){/*双击事件代码*/}}) DefaultTableModel model =new DefaultTableModel(colummNames,0){ public boolean isCellEditable(int row,int column){return false;}}; jTable1.setModel(model);
刚好用到 table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { rowIndex = table.rowAtPoint(e.getPoint()); columnIndex = table.columnAtPoint(e.getPoint()); // your code } } }
通过TableCellRenderer可以实现楼主的功能!!
table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { rowIndex = table.rowAtPoint(e.getPoint()); columnIndex = table.columnAtPoint(e.getPoint()); // your code } } } 这样就应该可以了,如果想要在鼠标出弹出窗口的话,可以用JPopMenu来显示 !
2为第几列getSubProcessParameterValueCellEditor()为得到编辑方式的方法,你可以在这里面定义JButton,不过得让这个JButton继承JFormattedTextField并重写setBounds方法.
public void setBounds(int x, int y, int width, int heigth){
super.setBounds(x, y, width, heigth);
b_chooser.setBounds(this.getWidth()*3/4, 0, this.getWidth()/4, this.getHeight());
}
b_chooser为按扭的定义名称
jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jTable1.addMouseListener(new MouseAdapter(){public void mouseClicked(MouseEvent e){/*双击事件代码*/}})
DefaultTableModel model =new DefaultTableModel(colummNames,0){ public boolean isCellEditable(int row,int column){return false;}};
jTable1.setModel(model);
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
rowIndex = table.rowAtPoint(e.getPoint());
columnIndex = table.columnAtPoint(e.getPoint());
// your code
}
}
}
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
rowIndex = table.rowAtPoint(e.getPoint());
columnIndex = table.columnAtPoint(e.getPoint());
// your code
}
}
}
这样就应该可以了,如果想要在鼠标出弹出窗口的话,可以用JPopMenu来显示 !