[英]JPanel taking whole JFrame size. BorderLayout
I have problem with my JPanel
, which alone takes the whole JFrame
space. 我的JPanel
存在问题,仅此一个就占用了整个JFrame
空间。 I want to add two JPanel
's in a single JFrame
. 我想在单个JFrame
添加两个JPanel
。 I'm helping myself with eclipse plugin WindowMaker, but I also tried to code the layout by hand - to no avail. 我正在使用Eclipse插件WindowMaker帮助自己,但我也尝试手动编写布局代码-无济于事。 There's no way that I can resize my JPanel
eg make it 50% of its size. 我无法调整JPanel
大小,例如使其占其大小的50%。 I read about this case and tried to understand LayoutManagers. 我了解了这种情况,并试图了解LayoutManagers。 But even if I put my JLabel
to corner or any specific side, nothing changes so far. 但是,即使我将JLabel
放在角落或任何特定的一侧,到目前为止,也没有任何改变。 Can somebody help me with that? 有人可以帮我吗?
Code sample: private JPanel contentPane; 代码示例:私有JPanel contentPane;
/**
* Create the frame.
*/
public GUI() {
setTitle("GALAXY INVADERS: CASTELO EDITION");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(200, 100, 1000, 600);
getContentPane().setLayout(new BorderLayout());
// init of the Panel
contentPane = new MyPanel2();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(300, 400));
setContentPane(contentPane);
}
MyPanel2
is a class which extends JPanel. MyPanel2
是扩展JPanel的类。
BorderLayout
has 5 available positions onto which components are added... BorderLayout
具有5个可用位置,在这些位置上添加了组件...
By default, the CENTER
position will occupy the whole available space of the container. 默认情况下, CENTER
位置将占据容器的整个可用空间。
Try placing you other components into different positions or try a different layout manager. 尝试将其他组件放置在不同位置或尝试使用其他布局管理器。
Take a look at Laying Out Components Within a Container for more details... 看一下在容器中布置组件的更多详细信息...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.