how can I scroll my JFrame using the JScrollbar?

情到浓时终转凉″ 提交于 2019-11-29 09:49:53
  1. Put all the components in one panel (instead of in the JFrame)
  2. Add this panel to a JScrollPane
  3. Add the JScrollPane to your frame.

I should be something like:

JPanel container = new JPanel();
container.add(panel1);
container.add(Panel2);
JScrollPane jsp = new JScrollPane(container);
frame.add(jsp);

It depends on the layout you are using with your JFrame. If you want to add working scrollbar to your panel you should look at the JScrollPane class and the Scrollable interface which must be implemented by scrollable components.

The How to use scroll panes chapter in the swing tutorial may also be an interesting reading: http://download.oracle.com/javase/tutorial/uiswing/components/scrollpane.html

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