我研究了如何更改JFrame上显示的jbutton的大小。JButton不改变尺寸
我想都button.setSize(200,200)和button.setPreferredSize(新维(200,200)),但它不会改变。下面的代码:
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Index extends JFrame{
private String title = "This is the motherfucking title";
Dimension dim = new Dimension(500,500);
public Index(){
this.setResizable(false);
this.setTitle(title);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(dim);
this.getContentPane().setBackground(Color.BLACK);
JButton button = new JButton("Button");
button.setSize(200,200);
this.add(button);
}
public static void main(String args[]){
Index ih = new Index();
ih.setVisible(true);
}
}
这里的结果:http://i.imgur.com/Llj0pfo.png
我在做什么错?
谢谢!这工作:) – Arcthor