java中 关于使用JSplitPane时遇到一个疑惑,求解
首先上代码publicclassTest1extendsJFrame{publicTest1(){this.setBounds(100,100,700,500);this...
首先上代码
public class Test1 extends JFrame
{
public Test1()
{
this.setBounds(100, 100, 700, 500);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
this.add(splitPane,BorderLayout.CENTER);
//向拆分窗口加入左右Panel(with BorderLayout)
JPanel leftPanel = new JPanel(new BorderLayout());
leftPanel.setBackground(Color.black);
JPanel rightPanel = new JPanel(new BorderLayout());
rightPanel.setBackground(Color.blue);
splitPane.add(leftPanel);
splitPane.add(rightPanel);
//向rightPanel里添加一个有按钮的Panel到north
JPanel apanel = new JPanel();
apanel.add(new JButton("测试"));
apanel.setBackground(Color.cyan);
rightPanel.add(new JPanel(),BorderLayout.SOUTH);
}
public static void main(String[] strs)
{
new Test1().setVisible(true);
}
}
执行过后,为什么添加到rightPanel的那个apanel 只显示很小一点,而且上面的测试按钮也不显示 展开
public class Test1 extends JFrame
{
public Test1()
{
this.setBounds(100, 100, 700, 500);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
this.add(splitPane,BorderLayout.CENTER);
//向拆分窗口加入左右Panel(with BorderLayout)
JPanel leftPanel = new JPanel(new BorderLayout());
leftPanel.setBackground(Color.black);
JPanel rightPanel = new JPanel(new BorderLayout());
rightPanel.setBackground(Color.blue);
splitPane.add(leftPanel);
splitPane.add(rightPanel);
//向rightPanel里添加一个有按钮的Panel到north
JPanel apanel = new JPanel();
apanel.add(new JButton("测试"));
apanel.setBackground(Color.cyan);
rightPanel.add(new JPanel(),BorderLayout.SOUTH);
}
public static void main(String[] strs)
{
new Test1().setVisible(true);
}
}
执行过后,为什么添加到rightPanel的那个apanel 只显示很小一点,而且上面的测试按钮也不显示 展开
2个回答
2013-05-13
展开全部
试试设置
pnlMain.setMinimumSize(new Dimension(widthNum, heightNum));
pnlMain.setMaximumSize(new Dimension(widthNum, heightNum));
pnlMain.setPreferredSize(new Dimension(widthNum,heightNum));
pnlMain.setMinimumSize(new Dimension(widthNum, heightNum));
pnlMain.setMaximumSize(new Dimension(widthNum, heightNum));
pnlMain.setPreferredSize(new Dimension(widthNum,heightNum));
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询