new JButton("Hello<br>World");

解决方案 »

  1.   

    倒!正准备自己来回答,已被抢答,还是感谢帮忙的兄弟。答案如下:
    It appears that my original answer to the multiline button question was not complete. When I wrote my original answer to the multiline button question I was using Java 1.1.7 and Swing 1.0.3, for which my answer remains valid. Many developers (myself included) are stuck using these older versions. However, it appears that newer versions of Swing do enable HTML rendering. Here are two suggestions sent in by two of JavaWorld's many astute readers: 
    Quite a few Swing components can render their contents with an HTML renderer. As a result, you can create a multiline button with the following code: 
    JButton b = new JButton("<html>Your<br>Name");-- Sebastian Fernandez 
    AND To solve the multiline button problem, simply write: 
    JButton myButton = new JButton("<html>Hello<p>World</html>");Be aware that all Swing components now support HTML. -- Tarek Hammoud