public static void main(String[] argv) throws NoSuchMethodException { f = new JFrame(); Container c = f.getContentPane(); c.setLayout(new BorderLayout()); c.add(new WordListScreen(null), BorderLayout.CENTER); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); showFrame(true); }
@SuppressWarnings("restriction") public static void enableAppleFullscreen(JFrame window) { window.pack(); window.setVisible(true); setAutoRequestFocus(window, true); if (javaVersion() == 7) { // work around bug in java 7 where top bar space is blank unless undecorated FullScreenUtilities.addFullScreenListenerTo( window, new FullScreenAdapter() { boolean working = false; @Override public void windowEnteredFullScreen(AppEvent.FullScreenEvent e) { if (working) { working = false; return; } ; if (!((JFrame) e.getWindow()).isUndecorated()) { working = true; Application.getApplication().requestToggleFullScreen(e.getWindow()); } } @Override public void windowExitedFullScreen(AppEvent.FullScreenEvent e) { if (working) { e.getWindow().dispose(); ((JFrame) e.getWindow()).setUndecorated(true); e.getWindow().pack(); e.getWindow().setVisible(true); Application.getApplication().requestToggleFullScreen(e.getWindow()); return; } ; if (((JFrame) e.getWindow()).isUndecorated()) { e.getWindow().dispose(); ((JFrame) e.getWindow()).setUndecorated(false); e.getWindow().setVisible(true); } } }); } FullScreenUtilities.setWindowCanFullScreen(window, true); }
public static void openFrame(Object frame) { boolean packFrame = false; if (packFrame) { ((JFrame) frame).pack(); } else { ((JFrame) frame).validate(); } // Center the window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = ((JFrame) frame).getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } ((JFrame) frame) .setLocation( (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); ((JFrame) frame).setVisible(true); }
public static void toFullScreen( JFrame window, GraphicsDevice gd, boolean tryAppleFullscreen, boolean tryExclusiveFullscreen) { if (appleEawtAvailable() && tryAppleFullscreen && appleOSVersion() >= 7 && // lion and above javaVersion() >= 7) { // java 7 and above System.out.println("trying to apple fullscreen"); enableAppleFullscreen(window); doAppleFullscreen(window); } else if (appleEawtAvailable() && // Snow Leopard and below OR apple java 6 and below TODO: test this on SL tryExclusiveFullscreen && gd.isFullScreenSupported()) { if (javaVersion() >= 7) setAutoRequestFocus(window, true); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setUndecorated(true); // window.setExtendedState(JFrame.MAXIMIZED_BOTH); gd.setFullScreenWindow(window); window.toFront(); Rectangle r = gd.getDefaultConfiguration().getBounds(); window.setBounds(r); // window.pack(); } else { // Windows and Linux TODO: test this window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setUndecorated(true); window.setSize(gd.getDisplayMode().getWidth(), gd.getDisplayMode().getHeight()); window.setLocation(0, 0); window.setExtendedState(JFrame.MAXIMIZED_BOTH); window.toFront(); } window.pack(); window.setVisible(true); }
public void init() { // 添加按钮 JPanel buttonPanel = new JPanel(); buttonPanel.add(okButton); mainPanel.setLayout(new GridLayout(0, 3)); mainWin.add(mainPanel, BorderLayout.CENTER); JFormattedTextField intField0 = new JFormattedTextField( new InternationalFormatter(NumberFormat.getIntegerInstance()) { protected DocumentFilter getDocumentFilter() { return new NumberFilter(); } }); intField0.setValue(100); addRow("只接受数字的文本框", intField0); JFormattedTextField intField1 = new JFormattedTextField(NumberFormat.getIntegerInstance()); intField1.setValue(new Integer(100)); // 添加输入校验器 intField1.setInputVerifier(new FormattedTextFieldVerifier()); addRow("带输入校验器的文本框", intField1); // 创建自定义格式器对象 IPAddressFormatter ipFormatter = new IPAddressFormatter(); ipFormatter.setOverwriteMode(false); // 以自定义格式器对象创建格式化文本框 JFormattedTextField ipField = new JFormattedTextField(ipFormatter); ipField.setValue(new byte[] {(byte) 192, (byte) 168, 4, 1}); addRow("IP地址格式", ipField); mainWin.add(buttonPanel, BorderLayout.SOUTH); mainWin.pack(); mainWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainWin.setVisible(true); }
/** * Test code. * * @param args First arg is the class name to create */ public static void main(String[] args) { try { Class type = null; Object instance = null; if (args.length > 0) { type = Class.forName(args[0]); instance = type.newInstance(); } else { type = TestClass.class; instance = new TestClass(); ((TestClass) instance).setObject(new TestClass()); } JFrame f = new JFrame(type.getName()); DynamicCustomizer custom = new DynamicCustomizer(type); custom.setObject(instance); f.getContentPane().add(new JScrollPane(custom)); f.pack(); f.setVisible(true); } catch (Exception ex) { ex.printStackTrace(); } }