jdk7.0以下swing最大化在linux和windows问题,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| FrameMain frame = new FrameMain(); boolean b = true; //当前操作系统 String os = UtilityHelper.getOperatingSystem(); if(StringHelper.isNullOrEmpty(os)) { }else { os = os.toLowerCase(); if (os.startsWith("linux")) { b = false; } } Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); if(b) { // Center the window Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); frame.setExtendedState(JFrame.MAXIMIZED_BOTH); }else { frame.setSize(screenSize); frame.setLocation(0,0); } frame.setVisible(true);
|