private void saveWindowState(String key, Frame frame) { if ((frame.getExtendedState() & Frame.MAXIMIZED_BOTH) == 0) { preferences.putInt(key + "-x", frame.getLocation().x); preferences.putInt(key + "-y", frame.getLocation().y); preferences.putInt(key + "-width", frame.getSize().width); preferences.putInt(key + "-height", frame.getSize().height); } }
public static void Field1(){ fieldT.Label(); fieldT.panel(); f1.setSize(400, 400); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); // 화면 픽셀 계산 Dimension frm = f1.getSize();//창 크기 계산 int xpos = (int)(screen.getWidth() / 2 - frm.getWidth() / 2); // 창 중앙 위치 계산 int ypos = (int)(screen.getHeight() / 2 - frm.getHeight() / 2); f1.setLayout(new GridLayout(4, 4));// 프레임 레이아웃 f1.setBackground(Color.cyan); //프레임 배경 f1.addWindowListener(new WEventHandler()); f1.addKeyListener(new KEventHandler()); f1.setResizable(false); for(int i =0;i<4;i++){ for(int j=0;j<4;j++){ f1.add(p[i][j]); } } f1.setLocation(xpos, ypos); f1.setVisible(true); }
void saveWindowLocations() { Frame frame = WindowManager.getFrame("B&C"); if (frame != null) Prefs.saveLocation(ContrastAdjuster.LOC_KEY, frame.getLocation()); frame = WindowManager.getFrame("Threshold"); if (frame != null) Prefs.saveLocation(ThresholdAdjuster.LOC_KEY, frame.getLocation()); frame = WindowManager.getFrame("Results"); if (frame != null) { Prefs.saveLocation(TextWindow.LOC_KEY, frame.getLocation()); Dimension d = frame.getSize(); Prefs.set(TextWindow.WIDTH_KEY, d.width); Prefs.set(TextWindow.HEIGHT_KEY, d.height); } frame = WindowManager.getFrame("Log"); if (frame != null) { Prefs.saveLocation(TextWindow.LOG_LOC_KEY, frame.getLocation()); Dimension d = frame.getSize(); Prefs.set(TextWindow.LOG_WIDTH_KEY, d.width); Prefs.set(TextWindow.LOG_HEIGHT_KEY, d.height); } }
/** * Centre the dialog box in the frame. This must be called after the size has been established, * i.e. after the buttons etc. are arranged and pack() is called */ public void centreInFrame() { Dimension frame_size = parent.getSize(); Point frame_location = parent.getLocation(); int centre_x = frame_location.x + frame_size.width / 2; int centre_y = frame_location.y + frame_size.height / 2; ; int xloc = centre_x - this.getSize().width / 2; int yloc = centre_y - this.getSize().height / 2; this.setLocation(new Point(xloc, yloc)); this.requestFocus(); }
private void centerOnScreen(Frame frame) { Point point = frame.getLocationOnScreen(); Dimension dimension = frame.getSize(); Dimension dimension1 = getSize(); point.x += (dimension.width - dimension1.width) / 2; point.y += (dimension.height - dimension1.height) / 2; Dimension dimension2 = Toolkit.getDefaultToolkit().getScreenSize(); if (point.x < 0 || point.y < 0 || point.x + dimension1.width > dimension2.width || point.y + dimension1.height > dimension2.height) { point.x = (dimension2.width - dimension1.width) / 2; point.y = (dimension2.height - dimension1.height) / 2; } setLocation(point.x, point.y); }
public CustomAttachmentDialog(AttachmentHandlerProperties properties) { super(PlatformUI.MIRTH_FRAME); this.parent = PlatformUI.MIRTH_FRAME; initComponents(); initPropertiesTable(); attachmentHandlerProperties = properties; classNameField.setText(attachmentHandlerProperties.getClassName()); classNameField.requestFocus(); classNameField.addFocusListener( new FocusAdapter() { @Override public void focusGained(FocusEvent e) { if (initialFocus) { classNameField.setCaretPosition(0); initialFocus = false; } } }); updatePropertiesTable(attachmentHandlerProperties.getProperties()); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setModal(true); Dimension dlgSize = getPreferredSize(); Dimension frmSize = parent.getSize(); Point loc = parent.getLocation(); if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) { setLocationRelativeTo(null); } else { setLocation( (frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y); } setVisible(true); }
/** Creates new form UserDialog */ public FirstLoginDialog(User currentUser) { super(PlatformUI.MIRTH_FRAME); this.parent = PlatformUI.MIRTH_FRAME; initComponents(); finishButton.setEnabled(false); userEditPanel.setUser(this, currentUser); jLabel2.setForeground(UIConstants.HEADER_TITLE_TEXT_COLOR); setModal(true); setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); this.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { finishButtonActionPerformed(null); } }); pack(); Dimension dlgSize = getPreferredSize(); Dimension frmSize = parent.getSize(); Point loc = parent.getLocation(); if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) { setLocationRelativeTo(null); } else { setLocation( (frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y); } usageStatsMoreInfoLabel.setToolTipText(UIConstants.PRIVACY_TOOLTIP); usageStatsMoreInfoLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); setVisible(true); }
/* Constructor : generate the Frame. */ public Interface() { frame = new Frame(); // Validate frames that have preset sizes // Pack frames that have useful preferred size info, e.g. from their layout if (packFrame) { frame.pack(); } else { frame.validate(); } // Center the window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 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.setVisible(true); };
/** Method declaration */ void main() { fMain = new Frame("HSQL Database Manager"); imgEmpty = createImage(new MemoryImageSource(2, 2, new int[4 * 4], 2, 2)); fMain.setIconImage(imgEmpty); fMain.addWindowListener(this); MenuBar bar = new MenuBar(); // used shortcuts: CERGTSIUDOLM String fitems[] = { "-Connect...", "--", "-Open Script...", "-Save Script...", "-Save Result...", "--", "-Exit" }; addMenu(bar, "File", fitems); String vitems[] = { "RRefresh Tree", "--", "GResults in Grid", "TResults in Text", "--", "1Shrink Tree", "2Enlarge Tree", "3Shrink Command", "4Enlarge Command" }; addMenu(bar, "View", vitems); String sitems[] = { "SSELECT", "IINSERT", "UUPDATE", "DDELETE", "--", "-CREATE TABLE", "-DROP TABLE", "-CREATE INDEX", "-DROP INDEX", "--", "-CHECKPOINT", "-SCRIPT", "-SET", "-SHUTDOWN", "--", "-Test Script" }; addMenu(bar, "Command", sitems); Menu recent = new Menu("Recent"); mRecent = new Menu("Recent"); bar.add(mRecent); String soptions[] = { "-AutoCommit on", "-AutoCommit off", "OCommit", "LRollback", "--", "-Disable MaxRows", "-Set MaxRows to 100", "--", "-Logging on", "-Logging off", "--", "-Insert test data" }; addMenu(bar, "Options", soptions); /* NB - 26052002 Restore is not implemented yet in the transfer tool */ String stools[] = {"-Dump", /*"-Restore",*/ "-Transfer"}; addMenu(bar, "Tools", stools); fMain.setMenuBar(bar); fMain.setSize(640, 480); fMain.add("Center", this); initGUI(); sRecent = new String[iMaxRecent]; Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); Dimension size = fMain.getSize(); // (ulrivo): full size on screen with less than 640 width if (d.width >= 640) { fMain.setLocation((d.width - size.width) / 2, (d.height - size.height) / 2); } else { fMain.setLocation(0, 0); fMain.setSize(d); } fMain.show(); // (ulrivo): load query from command line if (defScript != null) { if (defDirectory != null) { defScript = defDirectory + File.separator + defScript; } txtCommand.setText(DatabaseManagerCommon.readFile(defScript)); } txtCommand.requestFocus(); }