免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1635 | 回复: 4
打印 上一主题 下一主题

JTable/TableCellRenderer [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-03-17 08:07 |只看该作者 |倒序浏览
Sorry to write in English.

I render all the cells (when the mouse gets clicken etc.) in a JTable using a TableCellRenderer.  But I need also to render the cells, when another button is clicked (so that there is some change on the JTable), does anybody know how to add the Listener?

Thanks in advance.

论坛徽章:
0
2 [报告]
发表于 2005-03-17 12:22 |只看该作者

JTable/TableCellRenderer

You can just add an ActionListener to the button.

论坛徽章:
0
3 [报告]
发表于 2005-03-18 22:10 |只看该作者

JTable/TableCellRenderer

The problem is:

...

class CrossTableCellRenderer extends DefaultTableCellRenderer {

        private Color c1 = new Color(160, 160, 255);
        private Color c2 = new Color(255, 160, 160);
        private Color c3 = new Color(255, 255, 255);

        private int row_;
        private int col_;

        public Component getTableCellRendererComponent(JTable t, Object v, boolean s, boolean f, int r, int c) {
                Component cell = super.getTableCellRendererComponent(t, v, s, f, r, c);

                if (s || f) {
                        row_ = r;
                        col_ = c;
                        cell.setBackground(c2);
                }
                else {
                        if (r == row_ || c == col_)
                                cell.setBackground(c1);
                        else
                                cell.setBackground(c3);
                   }

                return cell;
        }
}

...

public void actionPerformed(ActionEvent e) {
               
                String cmd = e.getActionCommand();

                if (cmd.equals("global pivoting")) {
                        mat.set_global();    // do some operation
                        table.repaint();
                }
...

If I click the "global pivoting" button, and the JTable table will be drawed, but in
the renderer the variables s (for selected) and f (for focus) do not change.

Could you give some advices in details.
Thanks a lot.

论坛徽章:
0
4 [报告]
发表于 2005-03-20 07:02 |只看该作者

JTable/TableCellRenderer

I would like to pay RMB 100 (I am afraid only to be able to do this by cash order, "hui kuan", this is a mtter of trust) for any clue that works for me or a full repair on my code, to get my code, give me an email adress.

Thanks.

论坛徽章:
0
5 [报告]
发表于 2005-04-01 17:03 |只看该作者

JTable/TableCellRenderer

是想让JTable 的绘制器响应事件吗?如果我没记错,这是不可能的,因为绘制器本身就鉴听事件,我以前是专门从事Swing控件开发的,在我的记忆中是这个样子。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP