-1

It's actually an question about this. How do I resize this now? I used this, I was able to resize my JPanel, but I can't find how to resize the table or scrollpane. I have 10 columns and the table just stays the same size.

Thanks in advance

Community
  • 1
  • 1
  • Override `getPreferredScrollableViewportSize()`, for [example](http://stackoverflow.com/search?tab=votes&q=%5bswing%5d%20%5bjtable%5d%20getPreferredScrollableViewportSize). – trashgod Feb 07 '17 at 20:39

1 Answers1

1

I was able to resize my JPanel, but I can't find how to resize the table or scrollpane.

The problem is that the JPanel uses a FlowLayout. A FlowLayout will respect the preferred size of any component added to the panel. So in the example code the table is displayed at its default preferred size.

A couple of solutions:

  1. There is no need for the panel. Just add the scrollpane directly to the frame. The table will grow/shrink as the frame size changes.
  2. Change the layout manager of the panel to one that will allow components added to it to grow to fill the available space. Again the table will grow/shrink as required.
  3. Override the getPreferredScrollableViewportSize(...) method of the JTable. This will override the default preferred size of the table. The table may grow/shrink depending of the layout manager used.
camickr
  • 321,443
  • 19
  • 166
  • 288