Java 如何使 JFrame 或 JPanel 可滚动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18765475/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 10:51:22  来源:igfitidea点击:

How to make JFrame or JPanel Scrollable

javaswingjframejpaneljscrollpane

提问by Laxman More

i have added multiple component on JPanel & then i add JPanel on JFrame.

我在 JPanel 上添加了多个组件,然后在 JFrame 上添加了 JPanel。

how to make window scrollable ?

如何使窗口可滚动?

so i can add more component at that frame or window .

所以我可以在那个框架或窗口添加更多组件。

回答by Josh M

Before adding your JPanel, put in a JScrollPanefirst:

在添加您的 之前JPanelJScrollPane先输入:

JPanel panel = ...;
JScrollPane scroll = new JScrollPane(panel);
frame.add(scroll, ...);

回答by piet.t

Just putting your JPanel in a JScrollPane and adding this to the JFrame should do the trick....

只需将您的 JPanel 放入 JScrollPane 并将其添加到 JFrame 中就可以解决问题....