Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
542 views
in Technique[技术] by (71.8m points)

java - Is it possible to detect a button clicked inside a table cell?

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?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...