2013-01-02 3 views
2

다음 코드JLabels에서 줄 바꿈을 적용하는 방법은 무엇입니까?

JLabel menuItemTitle = new JLabel("How to Find Waist"); 
    JLabel menuItemDescription = new JLabel("Take the Neck measurement with your shoulders down and relaxed.\n Looking straight ahead rap the tape around the smallest point, below the Larynx, and sloping down slightly toward the front.\nTry a few spots to get the lowest number, and where it feels the most natural."); 

     JPanel northPanel = new JPanel(); 
     northPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); 
     northPanel.add(menuItemTitle); 

     JPanel centerPanel = new JPanel(); 
     centerPanel.setLayout(new FlowLayout()); 
     centerPanel.add(menuItemDescription); 


     JDialog dialog = new JDialog(); 
     dialog.setLayout(new BorderLayout()); 
     dialog.add(northPanel,"North"); 
     dialog.add(centerPanel,"Center"); 

       dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
       dialog.setLocationRelativeTo(null); 
       dialog.pack(); 
       dialog.setVisible(true); 

내가 필요한 이스케이프 문자를 추가했지만이 라인을 위반하지 않는에서 참조하시기 바랍니다. JLabel에서 LineBreaks를 어떻게 추가 할 수 있습니까? 나는 HTML을 사용하여 위에서도 시도했다. 그러나 그것은 또한 실패했다. 도와주세요.

갱신

HTML 버전

menuItemDescription = new JLabel("<html>Take the Neck measurement with your shoulders down and relaxed.</br> Looking straight ahead rap the tape around the smallest point, below the Larynx, and sloping down slightly toward the front.</br>Try a few spots to get the lowest number, and where it feels the most natural.</html>"); 
+0

당신이 HTML 버전을 게시 할 수 이런 방식으로 JLabel의 내부에 HTML 코드를 사용할 수 있습니다. – Goibniu

+0

중복 : http://stackoverflow.com/questions/1090098/newline-in-jlabel –

+0

@Goibniu : 확인. 편집 –

답변

5

당신은 그 일을해야하기 때문에,

JLabel label = new JLabel("<html>Welcome to<br>Stackoverflow</html>"); 
+0

답변 주셔서 감사합니다. Undra :) –

+1

자동 줄 바꿈을 위해 본문에'style = 'width : 120px;''를 사용하십시오. 자세한 내용 및 데모는 [이 답변] (http://stackoverflow.com/questions/7861724/is-there-some-word-wrap-property-of-jlabel-exist/7861833#7861833)을 참조하십시오. –

관련 문제