Can I make a JTable column without borders?

I created a column with cells that contain JTextArea + A JButton inside it, as you can see in the image below in column 3:

alt text

But I ran into a lot of problems with my CellRenderer and CellEditor when updating the cell values ​​in this column, since my code is a bit more complicated. So instead, I want to replace this column with 2 columns. One column with normal String cells and the other with JButton cells , but these 2 columns should be the same as column 3 in the image above. So my questions are:

1. How can I combine the headers of two columns together?

2. How to remove the left borders of a JButtons column?

If they are fixed, then in this case 2 columns will have the same appearance as the above image + updating cell values ​​will be much easier.

-------------------------------- Editing: Problems with sample code:

Ok guys ... you asked for it. My code is huge, but if you can help me fix it, it will be perfect. I created a trial version of jar for my problem and included my source code. You can download it here:

Jar example

The problem is that I use a button to sort the rows of the table (move them up / down), but when I do this, some of the values ​​of the moved cells are not updated!

You can see the following screenshot: alt text The problem in the editor I use ... But I can not fix it.

+5
2

UPDATE ButtonCellRenderer ( 4) , 2, 3. , .

, , , , , . , JTextArea ( JTextField). , , . .

, getHeaderRect(int col) of JTableHeader, super.getHeaderRect() . paint() BasicTableHeaderUI, .

, , .

, . , .. .

EDIT. Metal LaF, :

    final TableCellRenderer defaultRenderer = getTableHeader().getDefaultRenderer();
    getTableHeader().setDefaultRenderer(new DefaultTableCellRenderer() {
        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            JLabel c = (JLabel) defaultRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (column == 1)
                c.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 0, Color.gray));
            else if (column == 2) {
                c.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 1, Color.gray));
                c.setText(null);
            } else
                c.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.gray));
            return c;
        }
    });
+2

JButton ( ), TableCellRenderer?

0

All Articles