2
  scrollPane = new JScrollPane(table);
  panel1.add( scrollPane,BorderLayout.CENTER );

Is there a way I can make the scrollPane bigger (wider) ?

razshan
  • 1,128
  • 12
  • 41
  • 59

3 Answers3

6
JScrollPane scrollPane = new JScrollPane(table, 
                                        JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                        JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JScrollBar bar = scrollPane.getVerticalScrollBar();
bar.setPreferredSize(new Dimension(40, 0));

This works. I figured it out.

Simulant
  • 19,190
  • 8
  • 63
  • 98
razshan
  • 1,128
  • 12
  • 41
  • 59
  • [Don't set the preferred size](http://stackoverflow.com/questions/7229226/should-i-avoid-the-use-of-setpreferredmaximumminimumsize-methods-in-java-swi). Override `getPreferredSize` instead. – user1803551 Feb 17 '16 at 13:33
2

When using Border Layout you don't control the size of the somponents in it Consider using GridBag Layout.

MByD
  • 135,866
  • 28
  • 264
  • 277
2

The JScrollPane is as big as the element it holds. You should make those element(s) wider.

Also, there is the setSize()-method. But you'll most likely want to use the setPreferredSize()-method as mentioned by mre.

Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111