2

解决了

嗨,伙计们,如果我有一个这样的程序:

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.

我该怎么做?

我尝试使用\nfor new 行,但这对我来说效果不佳。

4

1 回答 1

0

Swing 组件理解一些 HTML

JLabel l1 = new JLabel( "<html><center>Welcome!<br>Thank you for using the<br>Swimming Pool Calculator.</center>");
于 2012-09-29T13:04:52.017 回答