1

Ok so I have this code:

//adding the panel which will hold the order table
JPanel orderPanel = new JPanel();
right.add(orderPanel);
JTable order = new JTable(orderData, orderColumnNames);
JScrollPane orderPane = new JScrollPane(order);
orderPanel.add(orderPane);

And I want to be able to remove this space :

The description of what I want to remove

I guess the space is made by the JScrollPane but i can't find any method to resize the JScrollPane to the JTable's size

Andrew V
  • 522
  • 10
  • 24
  • have you tried this http://stackoverflow.com/questions/13213645/set-size-of-jtable-in-jscrollpane-and-in-jpanel-with-the-size-of-the-jframe and this http://stackoverflow.com/questions/6234530/problems-with-jtable-and-jscrollpane-size ? – nikis Feb 21 '14 at 18:26
  • ty nikis i wanted to do it without setprefferedsize but apparently i need to use it – Andrew V Feb 21 '14 at 18:35

1 Answers1

3

For the reasons adduced here, don't of invoke setPreferredSize(). Instead, override getPreferredScrollableViewportSize() to return the desired size.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045