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

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

razshan
  • 1,118
  • 11
  • 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
  • 18,114
  • 7
  • 59
  • 94
razshan
  • 1,118
  • 11
  • 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
  • 133,244
  • 25
  • 260
  • 270
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,069
  • 15
  • 82
  • 110