繁体   English   中英

如何在JLabels中应用换行符?

[英]How to apply line breaks in 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);

我已经添加了必需的转义字符,但没有中断。 如何在JLabels中添加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>");

您可以通过这种方式在JLabel中使用HTML代码

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM