2017-11-24 17 views
1

My JLabelのhudHeaderが左に揃っていません。ここでJLabelが左に揃えられていません

は、それが現時点では次のようになります。 enter image description here

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); 

} 
+0

https://stackoverflow.comしてみてください/ questions/9212155/BoxLayoutの中心としてjava-boxlayout-panels-alignment –

+0

私はすでに試してみましたが、次の行は何も変わりません:-( setMaximumSize(新しい寸法(200,600)); setAlignmentX(Component.LEFT_ALIGNMENT); – altab

+0

JPanelsを追加するだけです。それは幅全体に渡って伸び、パネルに一列に並んだラベルを追加することができます。 –

答えて

1

そうではない:それは、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); 
+0

2番目のオプションで動作します。私はSwingConstants.LEFTの代わりにComponent.LEFT_ALIGNEMENTを使用していました。 – altab

関連する問題