解决了
嗨,大家好,如果我有一个像这样的程序:
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
用于新行,但对我而言效果不佳。 最佳答案
Swing组件了解一些HTML
JLabel l1 = new JLabel( "<html><center>Welcome!<br>Thank you for using the<br>Swimming Pool Calculator.</center>");
关于java - 如何格式化我的文字?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12652919/