首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Java项仅在调整窗口大小后显示

Java项仅在调整窗口大小后显示
EN

Stack Overflow用户
提问于 2012-01-07 23:07:29
回答 1查看 28.5K关注 0票数 20

我在一帧中有2个JPanels。第一个面板包含按钮等java项。我添加的两个按钮会出现,但JSpinner会在我调整窗口大小后出现。我猜这也会发生在我将添加的其他项目上。我该如何解决这个问题呢?

代码语言:javascript
复制
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);
}
}
EN

回答 1

Stack Overflow用户

发布于 2014-02-22 09:55:03

在最后添加setVisible(true),它就可以工作了。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8770617

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档