JPanel Form扩展以填补JScrollpane - 失败的目的

时间:2011-08-21 17:56:31

标签: java swing user-interface jscrollpane

我正在创建一个JPanel表单,其中包含其他几个JPanel。我想将它放在JScrollPane中。然后我想将JScrollPane放入JTabbedPane作为其中一个选项卡。我遇到了一个问题 - 即使我已经设置了尺寸,首选尺寸,最大尺寸等,我的JPanel形式在放入滚动窗格时会逐渐扩大。

1 个答案:

答案 0 :(得分:1)

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正在扩展,也可以更改框架的大小。