2015-04-17 78 views
3
import java.awt.Dimension; 

import javax.swing.JButton; 
import javax.swing.JFrame; 


public class Example { 

public static void main(String args[]){ 
    JFrame frame = new JFrame(); 
    frame.setResizable(false); 
    frame.setMinimumSize(new Dimension(200,150)); 
    frame.setLocationRelativeTo(null); 
    frame.setLayout(null); 
    frame.setVisible(true); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

    JButton exampleBtn1 = new JButton("set"); 
    exampleBtn1.setBounds(10, 10, 70, 10); 
    frame.add(exampleBtn1); 

    JButton exampleBtn2 = new JButton("set"); 
    exampleBtn2.setBounds(10, 30, 50, 10); 
    frame.add(exampleBtn2); 
} 
} 

此代码显示带有2个JButton的JFrame,每个显示文本“set”垂直切割一点。但我不能得到水平相同的结果和JButton exampleBtn2是我的问题的一个例子。JButton.setText横向切割

如何让exampleBtn2能够以水平方向显示所有文本?我想要得到与垂直相同的结果:即使JButton大小很小,以显示我想看到的所有文本,但不会被点重复。

+0

为什么你想要么这些的?希望看到所有文字更为典型。 – Radiodef

+0

您必须替换负责呈现文本的UI委托,但这使用库调用来执行实际渲染 – MadProgrammer

回答

1

你可以尝试使用:

exampleBtn2.setMargin(new Insets(0, 0, 0, 0)); 
+0

我正在寻找该解决方案,谢谢 – Periit

0

你可以尝试较小的字号有:

exampleBtn1.setFont(new Font("Arial", Font.PLAIN, 7));