我想将我的按钮调整为相同大小,然后放置在 JApplet 上的面板中。我试过使用
public void init() {
// TODO start asynchronous download of heavy resources
JButton btnWestern=new JButton("Western");
JButton btnPop=new JButton("Pop");
GridBagConstraints c4=new GridBagConstraints();
JPanel jPanel1 = new JPanel();
getContentPane().setLayout(new java.awt.GridBagLayout());
jPanel1.setLayout(new java.awt.GridBagLayout());
c4.gridx = 0;
c4.gridy = 0;
c4.insets = new Insets(36, 10, 0, 249);
jPanel1.add(btnWestern, c4);
c4.gridx = 0;
c4.gridy = 1;
c4.insets = new Insets(33, 10, 0, 249);
jPanel1.add(btnPop, c4);
add(jPanel1, new java.awt.GridBagConstraints());
}
当我跑步时,这就是我得到的
但我注意到,如果我将按钮文本更改为相同或长度相同,例如
JButton btnWestern=new JButton("Button1");
JButton btnPop=new JButton("Button2");
我得到了想要的输出
我该怎么做才能确保按钮的文本长度不同,按钮大小相同?