JPanel 表单扩展以填充 JScrollpane - 违背了目的

发布于 2024-11-30 22:52:53 字数 163 浏览 1 评论 0原文

我正在创建一个 JPanel 表单,其中将包含几个其他 JPanel。我想将其放置在 JScrollPane 中。然后我想将 JScrollPane 放入 JTabbedPane 作为选项卡之一。但我遇到了一个问题——即使我设置了大小、首选大小、最大大小等,我的 JPanel 表单在放置在滚动窗格中时也会展开。

I am creating a JPanel form which will contain several other JPanels. I want to place this inside a JScrollPane. Then I want to place the JScrollPane into a JTabbedPane as one of the tabs. I'm having a problem though -- my JPanel form winds up expanding when placed in the scrollpane even though I have set size, preferredsize, maximumsize, etc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江湖正好 2024-12-07 22:52:53
public class test
{

private static JFrame frame = new JFrame();
private static JTabbedPane pane0 = new JTabbedPane();
private static JScrollPane pane1 = new JScrollPane();
private static JPanel pane2 = new JPanel();
//add the rest of your JPanels here

public static void main(String[] args)
{
     frame.setSize(400,400);
     //add all the other attributes here
     frame.add(pane0);
     pane0.add(pane1);
     pane1.add(pane2);
     //go ahead and add the rest of your panels here
     frame.pack();//resizes the frame so that its subcomponents fit well inside.
}
}//this last bracket is for the class itself.  Sorry i couldn't tab everything the right          //way.

这就是你想做的吗?这就是我从你的问题中了解到的。顺便说一句,如果您的 JPanel 正在扩展,请同时更改框架的大小。

public class test
{

private static JFrame frame = new JFrame();
private static JTabbedPane pane0 = new JTabbedPane();
private static JScrollPane pane1 = new JScrollPane();
private static JPanel pane2 = new JPanel();
//add the rest of your JPanels here

public static void main(String[] args)
{
     frame.setSize(400,400);
     //add all the other attributes here
     frame.add(pane0);
     pane0.add(pane1);
     pane1.add(pane2);
     //go ahead and add the rest of your panels here
     frame.pack();//resizes the frame so that its subcomponents fit well inside.
}
}//this last bracket is for the class itself.  Sorry i couldn't tab everything the right          //way.

Is this what you're trying to do? That's what i understood from your question. By the way, if your JPanel is expanding, change the size of your frame as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文