2013-11-23 40 views
0

我有这样的代码添加图像形象定位摇摆

JFrame note=new new JFrame(); 
JLabel label5=new JLabel(); 
label5.setIcon(new ImageIcon(searchresult.class.getResource("/images/expired.png"))); 
label5.setBounds(200,500,450,100); 
note.add(label5); 

结果我得到的是这种enter image description here

我试图改变bounds为其他值但图像没有变化位置。图像保持在同一位置。

我做错了什么?

回答

1

您尚未将布局设置为框架。

note.setLayout(new FlowLayout()); 

这将帮助你拖动图像(或任何你想添加的成分)center

+0

完全忘了..thnx提醒 –

+0

它应该是null ...'note.setLayout(null);',如果你将它设置为布局管理器,它将不允许你自由设置边界,因为布局管理器是控制它的人...所以通过将布局设置为null,您可以完全控制。 – bakriawad