java jpanel 无法运行
我正在尝试在 JPanel 中创建一个 4x5 网格,该网格位于 EAST 的 BORDERLAYOUT 上...所以这里是图片:
这是代码:
setLayout( 新的 BorderLayout() );
JPanel invOne = new JPanel(newGridLayout(4,5));
JPanel 游戏 = new JPanel();
add("中心",invOne); 添加(“东方”,游戏); 添加(“南”,c);
for (int i = 0, j = 20; i < 20; i = i+1, j = j-1) {
invOne.add(new JButton("SLOT " + j));
}
你所看到的,库存槽与游戏面板重叠,这是不应该发生的,因为游戏面板位于 BorderLayout 的中心,而库存面板(invOne)位于 BorderLayout 的东边,所以我不知道为什么会这样重叠...
有帮助吗?
I'm trying to make a 4x5 Grid within a JPanel that is on a BORDERLAYOUT in EAST... soo here is pic:
Here is the code:
setLayout( new BorderLayout() );
JPanel invOne = new JPanel(newGridLayout(4,5));
JPanel game = new JPanel();
add("Center",invOne); add("East", game); add("South", c);
for (int i = 0, j = 20; i < 20; i = i+1, j = j-1) {
invOne.add(new JButton("SLOT " + j));
}
As you can see the invinventory slots are OVERLAPPING the game panel which should NOT happen because the game panel is in the CENTER of the BorderLayout and the Inventory panel (invOne) is on the EAST of the BorderLayout so I don't know why it's overlapping...
help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它是
add(invOne, BorderLayout.CENTER);
。您应该使用 BorderLayout 类中的常量而不是字符串。it's
add(invOne, BorderLayout.CENTER);
. You should use constants from BorderLayout class instead of strings.