是否可以检测在表格单元格内单击的按钮? [英] Is it possible to detect a button clicked inside a table cell?

查看:119
本文介绍了是否可以检测在表格单元格内单击的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个swing应用程序,其中我有一个表格,我正在放置一个可以包含按钮的面板。代码如下:

I a swing application in which i have a table inside it i'm putting a panel that can contain a button.The code is follow

 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;

}

我的问题是我可以检测到按钮上的点击是否包含在面板内?
我问的是技术上是否可行?

My question is can i detect a click on a button that contains inside the panel or not? I'm asking about if it's possible technically or not?

谢谢

推荐答案


在我的单元格中,我有两个按钮和三个标签;它们都在一个面板中。

In my cell, I have two buttons and three labels; they are all in one panel.

使用 TableCellRenderer TableCellEditor 。在这个完整的示例中, StatusEditor 查询封闭的 StatusPanel 并在其 getCellEditorValue()的实现中返回一个合适的值。

You are correct to use a TableCellRenderer and TableCellEditor. In this complete example, the StatusEditor queries the enclosing StatusPanel and returns a suitable value in its implementation of getCellEditorValue().

这篇关于是否可以检测在表格单元格内单击的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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