为什么我的 JFrame 不显示? [英] Why is my JFrame not showing?
本文介绍了为什么我的 JFrame 不显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很确定我以前这样做过,但由于某种原因,当我运行它时 JFrame 不会出现.
I'm pretty sure I've done it this way before, but for some reason, the JFrame won't show up when I run it.
JLabel originalString = new JLabel("Original String: "
+ str.getMutator());
JLabel currentString = new JLabel("Current String: "
+ str.getMutator());
JLabel finalString = new JLabel("Final String: " + str.getTarget());
JPanel panel = new JPanel();
panel.add(originalString);
panel.add(currentString);
panel.add(finalString);
JFrame frame = new JFrame("Mutating String!");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
推荐答案
尝试设置大小或检查组件的首选大小,可能是因为您调用了 pack().
Try to set size or check with the preferred size of your components probably because you call pack().
frame.setSize(x, y);
frame.setSize(x, y);
这篇关于为什么我的 JFrame 不显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文