【问题标题】:Replace boolean check-box in a JTable with an image-icon checkbox用图像图标复选框替换 JTable 中的布尔复选框
【发布时间】:2013-12-31 15:17:07
【问题描述】:

你好,我和他有同样的问题。

Trying to replace boolean check-box in a JTable with an image-icon checkbox

但我已经部分解决了这个问题:

table.getColumnModel().getColumn(i).setCellRenderer(new CustomBooleanCellRenderer());           
table.getColumnModel().getColumn(i).setCellEditor(new CustomBooleanCellEditor());

并且可以工作...但我无法将图标居中...而且我无法自动更新,知道吗?

【问题讨论】:

    标签: java swing jtable tablecellrenderer


    【解决方案1】:

    基本上,在渲染器和编辑器中,你需要将JCheckBoxhorizontalAlignment设置为CENTER

    public class CustomCheckBox extends JCheckBox {
    
        //...
    
        public CustomCheckBox() {
            //...
            setHorizontalAlignment(CENTER);
        }
    

    (nb- 自定义编辑器和渲染器都使用CustomCheckBox)

    【讨论】:

    • 我确信我可以为你创造更多(问题);)
    猜你喜欢
    • 2013-04-04
    • 1970-01-01
    • 2012-06-06
    • 2016-04-20
    • 2014-01-21
    • 2011-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多