Java 显示30px高的JPanel,然后用minecraft填满剩余空间
我正在尝试制作一个顶部带有30px JPanel的JFrame,然后在下面添加Minecraft小程序,两者都需要自动调整大小,我正在尝试使用GridBagLayout实现这一点,到目前为止,我已经:Java 显示30px高的JPanel,然后用minecraft填满剩余空间,java,swing,minecraft,gridbaglayout,thread-sleep,Java,Swing,Minecraft,Gridbaglayout,Thread Sleep,我正在尝试制作一个顶部带有30px JPanel的JFrame,然后在下面添加Minecraft小程序,两者都需要自动调整大小,我正在尝试使用GridBagLayout实现这一点,到目前为止,我已经: public void start(Applet mcApplet, String user, String session) throws MalformedURLException { JLabel label = new JLabel(); Thread animation
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);
}
我建议您使用,并将您的30px面板置于
北部
位置,同时将您的Minecraft小程序置于中心
位置。尝试将权重设置为1.0(即,使用100%的额外空间)()也尝试为每个组件使用不同的GridBagConstraint。一个用于菜单,另一个用于AppleTrap。AppleThraps约束的权重应该设置为1.0。谢谢,我会尝试这种工作方式,但是minecraft的框架被拉伸到4000px宽,因为menu.png是4000px,我如何防止这种情况发生?1)为了尽快获得更好的帮助,发布一个。2) 不要阻止EDT(事件调度线程)-发生这种情况时,GUI将“冻结”。不要调用Thread.sleep(n)
为重复任务执行Swing计时器,或为长时间运行的任务执行SwingWorker
。有关更多详细信息,请参阅。我已经有一段时间没有研究北面板的BorderLayout
行为了,但也许BorderLayout
更合适-30px面板位于北位置,小程序位于中间。