JTable column size

M

moongeegee

I have a table contains many columns. One of columns contains
checkbox. I have tried the following code to set the size, but the
size is still too big. Please advise. Thanks.

table.getColumnModel.getColumn(4).setPreferredWidth(5);
or

table.getColumnModel.getColumn(4).setPreferredWidth(1); <== the
smallest number I can set.
 
R

Roedy Green

I have a table contains many columns. One of columns contains
checkbox. I have tried the following code to set the size, but the
size is still too big. Please advise. Thanks.

Perhaps the problem is that JCheckBox has a label, and some space to
separate the label from the label. I take it you have an empty label?

I take it by "checkbox" you really mean JCheckBox.

To get it smaller, I think you will have to create your own label-less
component, cannibalising or overriding the JCheckBox code, and writing
a custom cell renderer.

You might even be able to do it simply with setPreferredSize
setMaximumSize to chop off the label.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top