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);
}
}
这段代码展示了一个带有两个JButton的JFrame,每个按钮都会显示一些被垂直切割的文本"set"。但是,我无法水平地获得相同的结果,其中JButton exampleBtn2就是我的问题所在。
如何使exampleBtn2能够以水平方向显示所有文本?我希望获得与垂直方向相同的结果:即使JButton大小太小而无法显示所有文本,我也希望看到它被切断,而不是被省略号替换。