2015-04-17 75 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));