gpt4 book ai didi

java - 如何以绝对定位将组件添加到 JComponent 中?

转载 作者:行者123 更新时间:2023-11-30 04:53:46 33 4
gpt4 key购买 nike

这是我当前的设置:

    private JComponent upperContent = new GeneralContent();
private JComponent lowerContent = new GeneralContent();
// GeneralContent extends JComponent

jframe.setLayout(new GridLayout(2, 0));
upperContent.setLayout(null);
lowerContent.setLayout(new GridBagLayout());
jframe.add(upperContent);
jframe.add(lowerContent)

lowerContent的所有组件都按预期显示,而upperContent没有显示我使用以下代码添加到其中的组件:

JLabel label=new JLabel();
upperContent.add(label);
label.setLocation(15,15);

我还使用了 label.repaint(); & upperContent.revalidate() 都不起作用

最佳答案

您可以使用空布局获得绝对定位。坏消息是,从那时起,一切都完全取决于你。

http://docs.oracle.com/javase/tutorial/uiswing/layout/none.html

关于java - 如何以绝对定位将组件添加到 JComponent 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9221051/

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