Linux安全网 - Linux操作系统_Linux 命令_Linux教程_Linux黑客

会员投稿 投稿指南 本期推荐:
搜索:
您的位置: Linux安全网 > Linux编程 > » 正文

JTable add button event.

来源: 未知 分享至:

//simple implement button action:

class TradeButton extends JButton implements TableCellRenderer {
         public   TradeButton()   {
           super();
           setOpaque(false);
         
        }


    @Override
         public   Component   getTableCellRendererComponent(JTable table, Object value,
              boolean   isSelected,
              boolean   hasFocus,
              int   row,
              int   column)   {
              if   (isSelected)   {
//                setForeground(table.getSelectionForeground());
//    setBackground(table.getSelectionBackground());
                System.out.println(row);
              }   else{
             System.out.println("nothing");
              }
                  setText(   (value   ==null)   ?   "SELL"   :   value.toString()   );
                  this.setToolTipText( "what what what??");
                  return   this;
              }

}

//good button action implement

class ButtonColumn extends AbstractCellEditor implements TableCellRenderer, TableCellEditor {
JButton renderButton;
JButton editButton;
String text;
ButtonColumn() {
renderButton = new JButton();
editButton = new JButton();
editButton.setFocusPainted(false);
}

public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
if (hasFocus) {
renderButton.setForeground(table.getForeground());
renderButton.setBackground(UIManager
.getColor("Button.background"));
} else if (isSelected) {
renderButton.setForeground(table.getSelectionForeground());
renderButton.setBackground(table.getSelectionBackground());
} else {
renderButton.setForeground(table.getForeground());
renderButton.setBackground(UIManager
.getColor("Button.background"));
}

renderButton.setText((value == null) ? "" : value.toString());
return renderButton;
}

public Component getTableCellEditorComponent(JTable table,
Object value, boolean isSelected, int row, int column) {
text = (value == null) ? "" : value.toString();
editButton.setText(text);
return editButton;
}

public Object getCellEditorValue() {
return text;
}
}

table.getColumn("321").setCellEditor(btnCol);
table.getColumn("321").setCellRenderer(btnCol);


Tags:
分享至:
最新图文资讯
1 2 3 4 5 6
验证码:点击我更换图片 理智评论文明上网,拒绝恶意谩骂 用户名:
关于我们 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 发展历史