2017-11-24 1 views
1

내 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를 시도 할 가능성이있는 HTML 본문의 여백처럼 보인다/questions/9212155/BoxLayout 센터와 같은 java-boxlayout-panels-alignment –

+0

이미 시도했지만 다음 라인에서는 아무 것도 변경되지 않습니다 :-( setMaximumSize (new Dimension (200,600)); setAlignmentX (Component.LEFT_ALIGNMENT); – altab

+0

그냥 JPanels를 추가하는 것입니다. 전체 너비에 걸쳐 늘어나게되고 패널에 왼쪽으로 레이블이 추가됩니다. –

답변

1

는 NOT SO : 그것은

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

두 번째 옵션과 함께 작동하지만 SwingConstants.LEFT 대신 Component.LEFT_ALIGNEMENT를 사용했습니다. 도움을 제공해 주셔서 감사합니다. – altab

관련 문제