0
table.setPreferredScrollableViewportSize(table.getPreferredSize());
JScrollPane scrollPane = new JScrollPane(table);
panel.add(scrollPane);

The scrollPane is not visible. If I add the

table.setPreferredScrollableViewportSize(table.getPreferredSize());

What do you think did I miss in the code? Because of I didn't put the

table.setPreferredScrollableViewportSize(table.getPreferredSize());

the JTable layout is not fitting on my panel.

Amarnath
  • 8,736
  • 10
  • 54
  • 81

1 Answers1

2

Instead of doing this,

table.setPreferredScrollableViewportSize(table.getPreferredSize());

Specify Dimension like this,

table.setPreferredScrollableViewportSize(new Dimension(400, 60));

UPDATE:

I think the above stated answer is not a good approach. You should never use setXXSize methods on a component. So please use this appraoch stated by @Kleopatra to set the Viewport size.

Community
  • 1
  • 1
Amarnath
  • 8,736
  • 10
  • 54
  • 81