JLabel 没有左对齐

JLabel not aligned to the left

我的 JLabel hudHeader 没有左对齐。

目前情况如下:

HUDisplay 扩展了 JPanel。

public HUDisplay() {

Border border = BorderFactory.createMatteBorder(0, 1, 0, 0, new Color(128, 128, 128));
Border margin = new EmptyBorder(8,8,8,8);
setBorder(new CompoundBorder(border, margin));
setBackground(new Color(250,250,250));

setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));


hudHeader = new JLabel("<html><b>Simulation informations</b><br />" +
        "<i style=\"font-size: 8px;\">Running for " + "0" + "s</i>" + "</html>");

hSeparation = new JSeparator(SwingConstants.HORIZONTAL);

add(hudHeader);
add(hSeparation);

setVisible(true);

}

不是这样:它看起来像 HTML 主体边距

NOT hudHeader = new JLabel(
NOT         "<html><body style='margin: 0 0 0 0;'><b>Simulation informations</b><br />" +
NOT         "<i style=\"font-size: 8px;\">Running for " + "0" + "s</i>" + "</html>");

但是可能会有一些可疑的东西,比如 RTL,所以也试试

hudHeader .setAlignment(SwingConstants.LEFT);