问题
scrollPane = new JScrollPane(table); panel1.add( scrollPane,BorderLayout.CENTER );
Is there a way I can make the scrollPane bigger (wider) ?
回答1:
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.
回答2:
When using Border Layout you don't control the size of the somponents in it Consider using GridBag Layout.
回答3:
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.
来源:https://stackoverflow.com/questions/6347768/how-to-increase-the-size-of-jscrollpane-pane