Make JCheckbox bigger..?

Christian 'fuzi' Orgler picture Christian 'fuzi' Orgler · Jan 22, 2011 · Viewed 10.8k times · Source

i want to make my JCheckboxes in a JTable bigger (for Touchscreen), but it doesn't change the size.

I tried it with

  • setPrefferedSize
  • setSize

What should I do?..

Answer

camickr picture camickr · Jan 22, 2011

I assume you mean you want a bigger check box. If so then you need to create images to represent the unselected and selected icons of the check box. Then you can create a renderer and editor using these icons. Finally you would need to increase the height of each row in the table. The code might look something like:

Icon normal = new ImageIcon(...);
Icon selected = new ImageIcon(...);
JTable table = new JTable(...);
table.setRowHeight(...);

TableCellRenderer renderer = table.getDefaultRenderer(Boolean.class);
JCheckBox checkBoxRenderer = (JCheckBox)renderer;
checkBoxRenderer.setIcon( normal );
checkBoxRenderer.setSelectedIcon( selected );

DefaultCellEditor editor = (DefaultCellEditor)table.getDefaultEditor(Boolean.class);
JCheckBox checkBoxEditor = (JCheckBox)editor.getComponent();
checkBoxEditor.setIcon( normal );
checkBoxEditor.setSelectedIcon( selected );