[英]How to align JLabel to the left of the JPanel?
我想把我的JLabel对齐到左边。
String lText = "<html><b><font color = white face = comic sans ms size = 20>mybook</font></b></html>";
JLabel label = new JLabel(lText);
label.setBorder(new EmptyBorder(25,0,25,500));
我尝试使用EmptyBorder做它,但它没有正确对齐。 我正在使用FlowLayout
FlowLayout
默认使用CENTER
对齐。 尝试为JLabel
JPanel
容器使用LEFT
对齐
myJPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
您可能希望设置JLabel的horizontalAlignment属性。 一种方法是通过它的构造函数。 尝试:
JLabel label = new JLabel(lText, SwingConstants.LEFT);
这也可以通过预期的setter方法完成:
label.setHorizontalAlignment(SwingConstants.LEFT);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.