我是一个 Swing 应用程序,其中有一个表格,我正在放置一个可以包含按钮的面板。代码如下
public class MyCellDataRenderer implements TableCellRenderer, TableCellEditor {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
MyCellData myCellData = (MyCellData) table.getValueAt(row, column);
JPanel panel = GridBagHelper.createPanel();
if (myCellData.isATableHeader()) {
panel.setBackground(myCellData.getCellBackgroundColor());
panel.add(myCellData.getContenant(), GridBagHelper.createGridBagConstraints(0, 0, 1, 1,
GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH));
return panel;
}
boolean condition=true;
if (condition==true) {
panel.setBackground(myCellData.getCellBackgroundColor());
panel.add(myCellData.getContenant(), GridBagHelper.createGridBagConstraints(0, 0, 1, 1,
GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH));
return panel;
}
panel.setBackground(myCellData.getCellBackgroundColor());
panel.add(myCellData.getContenant(), GridBagHelper.createGridBagConstraints(0, 0, 1, 1,
GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH));
return panel;
}
我的问题是我是否可以检测到对面板内包含的按钮的点击? 我问的是技术上可行吗?
谢谢
最佳答案
In my cell, I have two buttons and three labels; they are all in one panel.
您使用 TableCellRenderer
and TableCellEditor
是正确的。在此完整example ,StatusEditor
查询封闭的 StatusPanel
并在其 getCellEditorValue()
实现中返回合适的值。
关于java - 是否可以检测在表格单元格内单击的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24367799/