Java 项仅在窗口调整大小后显示
我在一个框架中有2个JPanels。第一个面板包含Java项目,如按钮等。我添加的两个按钮出现,但JSpinner在我调整窗口大小时出现。我想这将发生在我将添加的其他项目中。我该如何解决这个问题?
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerListModel;
import javax.swing.SpinnerNumberModel;
public class StartingPoint {
static JFrame window;
static DrawingArea draw;
static JButton b1, b2;
static JPanel userInt;
static JSpinner gravitySpinner;
public static void main(String[] args) {
window = new JFrame("Ball");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(600, 400);
window.setLayout(new BorderLayout());
window.setVisible(true);
draw = new DrawingArea();
window.add(draw, BorderLayout.CENTER);
userInt = new JPanel();
window.add(userInt, BorderLayout.NORTH);
b1 = new JButton("Start");
b2 = new JButton("aaa");
b1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
draw.setUp();
}
});
userInt.add(b1);
userInt.add(b2);
SpinnerNumberModel gravityModel = new SpinnerNumberModel(.9, .1, 2, .1);
gravitySpinner = new JSpinner(gravityModel);
userInt.add(gravitySpinner);
}
}