wolpe
wolpe

Reputation: 11

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.

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.

Upvotes: 0

Views: 1214

Answers (1)

camickr
camickr

Reputation: 324108

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.

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.

Upvotes: 3

Related Questions