简体   繁体   English

Java Swing JTable更改单元格边框

[英]java Swing JTable change cell Border

I would like to create a JTable that can change the border color of the outer highlighted cells on the press of a Button. 我想创建一个JTable,可以按一下Button来更改外部突出显示的单元格的边框颜色。

I already found out how to make the button and get the information for the cells that have to be changed like this: 我已经发现了如何制作按钮并获取必须像这样更改的单元格的信息:

        frame.add(new JButton(new AbstractAction("Create Border "){ 

        private static final long serialVersionUID = 1L;

        private void createBorder(){
            System.out.println(table.getSelectedColumn());
            System.out.println(table.getSelectedRow());
            System.out.println(table.getSelectedRowCount());
            System.out.println(table.getSelectedColumnCount());
            System.out.println(table.getSelectedRows()[0]);
            System.out.println(table.getSelectedColumns());             

        }

        @Override
        public void actionPerformed(ActionEvent e){
            createBorder();
        }

    }), BorderLayout.SOUTH);
    frame.pack();
    frame.setLocation(150,150);
    frame.setVisible(true);

}

what's left now is to somehow get the individual cells and change their border. 现在剩下的就是以某种方式获取单个细胞并更改其边界。

So far i only found solutions for changing the border at the creation of the table through the renderer. 到目前为止,我只找到了通过渲染器在创建表时更改边框的解决方案。

i only found solutions for changing the border at the creation of the table through the renderer. 我只找到了通过渲染器在创建表时更改边框的解决方案。

Another approach might be to overriding the prepareRenderer(...) method of the JTable , so you don't need to create a custom renderer for each type of data. 另一种方法可能是重写JTableprepareRenderer(...)方法,因此您无需为每种数据类型创建自定义渲染器。

Check out Table Row Rendering for some examples of this approach. 查看“ 表行渲染”以了解此方法的一些示例。 One example shows how to place a border around the entire row instead of each cell. 一个示例显示了如何在整个行而不是每个单元格周围放置边框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM