954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to set fix size to button cell

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

dophine
Light Poster
26 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

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;
    }
}
Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You