How can I get rid of the gray area that is under/to the right of JTable cells when there are only a few cells?

Sandip Chitale

The 'gray area to the right' happens when the column resize policy is AUTO_RESIZE_OFF. It is controlled using the following JTable API.

public void sizeColumnsToFit(int policy)

If you set any other policy as per JavaDoc API that problem should go away.

For the 'gray area under' you need to do -

JPanel p = new JPanel(new BorderLayout());
JTable table = new JTable(/*your table model etc*/);
JScrollPane sp = new JScrollPane(table);
p.add(sp, BorderLayout.CENTER);