有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何格式化文本?

已解决

大家好,如果我有一个这样的计划:

import java.awt.*;
import javax.swing.*;

public class Tab extends JFrame
{
    public Tab()
    {
        super ("Swimming Pool Calculator");

        JTabbedPane tab = new JTabbedPane();

        // constructing the first panel
        JLabel l1 = new JLabel( "Welcome to blah,blah!", SwingConstants.CENTER); 

        JPanel p1 = new JPanel();
        p1.add( l1 );
        tab.addTab( "Tab#1", null, p1, " Panel #1" );

        // constructing the second panel
        JLabel l2 = new JLabel("Welcome to JTabbedPaneDemo",SwingConstants.CENTER);
        JPanel p2 = new JPanel();
        p2.setBackground( Color.blue );
        p2.add( l2 );
        tab.addTab( "Tab#2", null, p2, " Panel #2" );

    }
}

我希望JLabel l1中的措辞是:

                                     "Welcome! 
                              Thank you for using the
                              Swimming Pool Calculator.

我该怎么做

我试图用\n作为新行,但对我来说效果不太好


共 (1) 个答案

  1. # 1 楼答案

    Swing组件理解一些HTML

    JLabel l1 = new JLabel( "<html><center>Welcome!<br>Thank you for using the<br>Swimming Pool Calculator.</center>");