use*_*415 4 java layout swing jlabel flowlayout
我想把我放在JLabel中的图像定位.这是我的代码:
public Main() {
setLayout (new FlowLayout());
image = new ImageIcon(getClass().getResource("title.gif"));
image1 = new JLabel(image);
image1.setAlignmentX(400);
image1.setAlignmentY(400);
add(image1);
}
Run Code Online (Sandbox Code Playgroud)
它显示图像,但显示线条
image1.setAlignmentX(400);
image1.setAlignmentY(400);
Run Code Online (Sandbox Code Playgroud)
不要做任何事情.我是Java的新手,感谢任何帮助.
(我希望得到一个例子.)
问题:
setAlignmentX(...)用于向容器建议组件沿x轴的对齐.如上所述,它取一个0.0f到1.0f的浮点数,0f表示左对齐,0.5f居中,右边1.0f.你肯定不想使用这种方法,或者它在这里是对应的.setBounds(...)或setLocation(...)方法完成.请告诉我们您的问题的更多细节,而不是您如何解决它,我们可能会更好地帮助您.