How to increase the size of JScrollPane pane?

允我心安 提交于 2019-12-11 00:33:36

问题


  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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!