在我看来,屏幕中间的GUI看起来是这样的。我一直在等待它们消失,真正的 GUI出现!
从Java 1.5开始,我们可以使用
Window.setLocationByPlatform(boolean)。哪一个..
设置此窗口是否应在下一次使该窗口可见时显示在本机窗口系统的默认位置还是当前位置(由getLocation返回)。此行为类似于未通过编程设置其位置而显示的本机窗口。如果未明确设置窗口的位置,则大多数窗口系统会级联窗口。一旦窗口显示在屏幕上,便确定了实际位置。
这是使用的简单代码:
import javax.swing.*;class WhereToPutTheGui { public static void initGui() { for (int ii=1; ii<4; ii++) { Jframe f = new Jframe("frame " + ii); f.setDefaultCloseOperation(Jframe.DISPOSE_ON_CLOSE); String s = "os.name: " + System.getProperty("os.name") + "nos.version: " + System.getProperty("os.version"); f.add(new Jtextarea(s,3,28)); // suggest a size f.pack(); // Let the OS handle the positioning! f.setLocationByPlatform(true); f.setVisible(true); } } public static void main(String[] args) { SwingUtilities.invokeLater( new Runnable() { public void run() { try { UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName()); } catch (Exception useDefault) {} initGui(); } }); }}


