gpt4 book ai didi

java - BorderLayout West Center East all 等宽

转载 作者:行者123 更新时间:2023-11-29 06:38:21 27 4
gpt4 key购买 nike

我将对象动态添加到面板,然后添加到我的边框布局。我需要西部、中心和东部的大小都相等。这是我目前所拥有的:

static int width = 300;//Screen width
static int height = width / 16 * 9;//Screen height
static int scale = 3;

private JFrame frame;

//player is an object from a Player Class will an arrayList of Items..
public void LoadPlayer(Player player){
int count = 1;
for (Items i : player.getAllItems()){
JPanel jp= new JPanel();
JLabel jlItem= new JLabel(i.getName());
BorderLayout bl = (BorderLayout) (mainPanel.getLayout()) ;
jp.add(jlItem);
jp.setBorder(BorderFactory.createLineBorder(Color.BLACK));

if (bl.getLayoutComponent(BorderLayout.WEST) == null){
mainPanel.add(jp,BorderLayout.WEST);
jp.setSize(frame.getWidth()/3, height);
System.out.println("adding item " + count+" to west panel");
}
else if (bl.getLayoutComponent(BorderLayout.CENTER) == null){
jp.setSize(frame.getWidth()/3, height);
mainPanel.add(jp,BorderLayout.CENTER);
System.out.println("adding item " + count+" to center panel");
}
else if (bl.getLayoutComponent(BorderLayout.EAST) == null){
mainPanel.add(jp.BorderLayout.EAST);
jp.setSize(frame.getWidth()/3, height);
System.out.println("adding item" + count+" to east panel");
}
count++;
}
}

我希望这会奏效,但没有奏效。我做了一些搜索,但似乎找不到任何说明您可以或不能设置 WESTCENTER 大小的内容东面板。有谁知道如何做到这一点?

最佳答案

I need the West, Center and East all to be equal size..

单行GridLayoutnested layoutBorderLayout.CENTER 中将实现这一目标。

关于java - BorderLayout West Center East all 等宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16642045/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com