import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class SimpleExample extends JFrame {
public SimpleExample() {
setTitle("Simple example");
setSize(500, 500);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JButton jb = new JButton("TEST");
jb.setBorderPainted(true);
jb.setBounds(5, 5, 1, 1); ---> This line
add(jb);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
SimpleExample ex = new SimpleExample();
ex.setVisible(true);
}
});
}
}
只需创建一个首选大小的简单按钮。该setBounds
方法似乎不起作用。我哪里错了?