[英]How do I increase the height of custom JPanel in a JFrame?
I want to increase the height of a custom JPanel
in a JFrame
. 我想在
JFrame
增加自定义JPanel
的高度。 I tried to use pa.setSize(700,200)
but it does not change anything. 我尝试使用
pa.setSize(700,200)
但它没有任何改变。
Here is the code: 这是代码:
JFrame f = new JFrame("Hello");
f.setResizable(true);
JPanel pa = new JPanel();
JButton btn = new JButton("Exit");
pa.setBackground(Color.red);
pa.setSize(700, 200);
f.setUndecorated(true);
f.getContentPane().add(pa, BorderLayout.NORTH);
f.setSize(new Dimension(700,700));
f.setLocation(500, 500);
f.setVisible(true);
它非常简单的解决方案,而不是pa.setsize()更改为pa.setPreferredSize(new Dimension(width,60));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.