Hi all,

there is a JTable and the cell in one column is set to button by set a customize cell render.
However, the size of the button occupies the whole cell region that is not what I want. How can I set fix size to it?

Thanks

I don't believe you can make the component not fill the cell, but you can add a border to the button in the custom renderer

class ButtonCellRenderer extends JButton implements TableCellRenderer {
    private Border MATTE_BORDER = BorderFactory.createMatteBorder(2, 3, 2, 3, 
      UIManager.getColor("Table.background"));

    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex) {

        setBorder(MATTE_BORDER);

        // ...

        return this;
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.