如何以绝对定位将组件添加到 JComponent 中?
这是我当前的设置:
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() 都不起作用
Here is my current settings:
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's all component are displayed as expected while upperContent didn't display the component that i was added to it by using the following code:
JLabel label=new JLabel();
upperContent.add(label);
label.setLocation(15,15);
i also used label.repaint(); & upperContent.revalidate() neither worked
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用空布局获得绝对定位。坏消息是从那时起一切都完全取决于你。
http://docs.oracle.com/javase/tutorial/uiswing/layout /无.html
You get absolute positioning with a null layout. The bad news is that everything is totally up to you from then on.
http://docs.oracle.com/javase/tutorial/uiswing/layout/none.html