显示30px高的JPanel,然后用minecraft填充其余的空间



我试图在顶部创建一个30px的JPanel的JFrame,然后在下面添加Minecraft Applet,两者都需要自动调整大小,我试图用GridBagLayout来实现这一点,到目前为止我有:

public void start(Applet mcApplet, String user, String session) throws MalformedURLException {
    JLabel label = new JLabel();
    Thread animation = new Thread();
    Dimension size = new Dimension(900, 540);
            JPanel basic = new JPanel(new GridBagLayout());
            basic.setPreferredSize(size);
            GridBagConstraints c = new GridBagConstraints();
            // ADD MINEBOOK MENU
            JLabel menu = new JLabel(new ImageIcon(new URL("http://modpacks.minebook.co.uk/images/menu.png")));
    if(!animationname.equalsIgnoreCase("empty")) {
        try {
            animation.start();
            label = new JLabel(new ImageIcon(animationname));
            label.setBounds(0, 0, size.width, size.height);
            fixSize(size);
            getContentPane().setBackground(Color.black);
            add(label);
            animation.sleep(3000);
            animation.stop();
        } catch (Exception e) {
            label.add(label);
        } finally {
            remove(label);
        }
    }
    try {
                appletWrap = new Launcher(mcApplet, new URL("http://www.minecraft.net/game"));
    } catch (MalformedURLException ignored) { }
    appletWrap.setParameter("username", user);
    appletWrap.setParameter("sessionid", session);
    appletWrap.setParameter("stand-alone", "true");
    mcApplet.setStub(appletWrap);
            mcApplet.setPreferredSize(size);
            c.fill = GridBagConstraints.HORIZONTAL;
            c.gridx = 0;
            c.gridy = 0;
            c.ipady = 30;
            basic.add(menu, c);
            c.fill = GridBagConstraints.BOTH;
            c.gridx = 0;
            c.gridy = 1;
            c.ipady = 0;
            basic.add(appletWrap, c);
            add(basic);
            pack();
    validate();
    appletWrap.init();
    appletWrap.start();
    fixSize(size);
    setVisible(true);
}

我建议你使用BorderLayout,并将你的30px面板放在NORTH位置,而你的Minecraft小程序在CENTER位置。

最新更新