我有一个秋千计划.首先我创建框架然后到那个框架我插入JPanel,它包含所有图形组件.不知何故,我无法绘制底部面板.我只有空窗.
@Override
public void run() {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new buildGUI());
frame.pack();
frame.getContentPane();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.getContentPane().validate();
frame.getContentPane().repaint();
}
.
.
.
public class buildGUI extends JPanel {
public void buildGUI() {
bottomPanel = new JPanel();
bottomPanel.setLayout(new GridBagLayout());
// build gui here, add components to bottomPanel
frame.add(bottomPanel);
}
@Override
public Dimension getPreferredSize() {
// this works
return new Dimension(800, 800);
}
@Override
protected void paintComponent(Graphics g) {
// here I want to draw my app gui
super.paintComponent(g);
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢