Jbutton上面的text 不用HTML的话 怎么搞出换行效果?像这样
-----------
| line1 |
| line2 |
-----------但是不要用html JButton b = new JButton("<html><font color=red>line1</font> <br> <font color=blue> line2</font></html>");请问有办法吗?
-----------
| line1 |
| line2 |
-----------但是不要用html JButton b = new JButton("<html><font color=red>line1</font> <br> <font color=blue> line2</font></html>");请问有办法吗?
如果一定要用html 你怎么改上面的字啊?
不用html的话大概需要重定义 paint() and getPreferredSize() 方法。
http://www.javaworld.com/javaworld/javaqa/2000-03/01-qa-button.htmlGood luck ~_+=======================================================================================import java.awt.BorderLayout;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;public class Jbutton { /**
* @param args
*/ public static void main(String[] args) {
// TODO Auto-generated method stub JFrame j = new JFrame();
JPanel p = new JPanel();
JButton b = new JButton();
b.setSize(10, 10);
b.setLayout(new BorderLayout());
JLabel label1 = new JLabel("Your");
JLabel label2 = new JLabel("Name");
b.add(BorderLayout.NORTH, label1);
b.add(BorderLayout.SOUTH, label2);
p.add(b);
j.add(p);
j.setVisible(true); }}
麻烦不麻烦不是关键 我做的是problem solving