List of usage examples for javax.swing JFrame getLocation
public Point getLocation()
From source file:components.FrameDemo2.java
public void showNewWindow() { JFrame frame = new MyFrame(); //Take care of the no window decorations case. //NOTE: Unless you really need the functionality //provided by JFrame, you would usually use a //Window or JWindow instead of an undecorated JFrame. if (noDecorations) { frame.setUndecorated(true);/*www . j a v a2 s . c om*/ } //Set window location. if (lastLocation != null) { //Move the window over and down 40 pixels. lastLocation.translate(40, 40); if ((lastLocation.x > maxX) || (lastLocation.y > maxY)) { lastLocation.setLocation(0, 0); } frame.setLocation(lastLocation); } else { lastLocation = frame.getLocation(); } //Calling setIconImage sets the icon displayed when the window //is minimized. Most window systems (or look and feels, if //decorations are provided by the look and feel) also use this //icon in the window decorations. if (specifyIcon) { if (createIcon) { frame.setIconImage(createFDImage()); //create an icon from scratch } else { frame.setIconImage(getFDImage()); //get the icon from a file } } //Show window. frame.setSize(new Dimension(170, 100)); frame.setVisible(true); }
From source file:FrameDemo2.java
public void showNewWindow() { JFrame frame = new MyFrame(); // Take care of the no window decorations case. // NOTE: Unless you really need the functionality // provided by JFrame, you would usually use a // Window or JWindow instead of an undecorated JFrame. if (noDecorations) { frame.setUndecorated(true);//from w w w .j a v a 2 s.c om } // Set window location. if (lastLocation != null) { // Move the window over and down 40 pixels. lastLocation.translate(40, 40); if ((lastLocation.x > maxX) || (lastLocation.y > maxY)) { lastLocation.setLocation(0, 0); } frame.setLocation(lastLocation); } else { lastLocation = frame.getLocation(); } // Calling setIconImage sets the icon displayed when the window // is minimized. Most window systems (or look and feels, if // decorations are provided by the look and feel) also use this // icon in the window decorations. if (specifyIcon) { if (createIcon) { frame.setIconImage(createFDImage()); // create an icon from scratch } else { frame.setIconImage(getFDImage()); // get the icon from a file } } // Show window. frame.setSize(new Dimension(170, 100)); frame.setVisible(true); }
From source file:com.tag.FramePreferences.java
public void install() { windowStateListener = new WindowStateListener() { public void windowStateChanged(WindowEvent e) { Object source = e.getSource(); if (source instanceof JFrame) { JFrame frame = (JFrame) source; int extendedState = frame.getExtendedState(); if (extendedState == JFrame.ICONIFIED) return; Preferences prefs = getPreferences(); prefs.putInt(KEY_EXTENDED_STATE, extendedState); }//from www . j av a2 s . c o m } }; frame.addWindowStateListener(windowStateListener); componentListener = new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { Preferences prefs = getPreferences(); Dimension size = frame.getSize(); prefs.putInt(KEY_WIDTH, size.width); prefs.putInt(KEY_HEIGHT, size.height); } @Override public void componentMoved(ComponentEvent e) { Preferences prefs = getPreferences(); Point location = frame.getLocation(); prefs.putInt(KEY_X, location.x); prefs.putInt(KEY_Y, location.y); } }; frame.addComponentListener(componentListener); }
From source file:org.zaproxy.zap.extension.openapi.ImportFromUrlDialog.java
public ImportFromUrlDialog(JFrame parent, ExtensionOpenApi caller) { super(parent, true); this.setTitle(Constant.messages.getString(MESSAGE_PREFIX + "title")); this.caller = caller; if (parent != null) { Dimension parentSize = parent.getSize(); Point p = parent.getLocation(); setLocation(p.x + parentSize.width / 4, p.y + parentSize.height / 4); }/* w w w . ja va2 s. com*/ // set up layout setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.anchor = GridBagConstraints.WEST; constraints.insets = new Insets(5, 5, 5, 5); buttonImport.addActionListener(this); buttonCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ImportFromUrlDialog.this.setVisible(false); ImportFromUrlDialog.this.dispose(); } }); // add components to the frame constraints.gridx = 0; constraints.gridy = 0; add(new JLabel(Constant.messages.getString(MESSAGE_PREFIX + "labelurl")), constraints); constraints.gridx = 1; constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weightx = 1.0; constraints.gridwidth = 2; fieldURL = addContextMenu(fieldURL); add(fieldURL, constraints); constraints.gridx = 0; constraints.gridy = 1; add(new JLabel(Constant.messages.getString(MESSAGE_PREFIX + "labeloverride")), constraints); constraints.gridx = 1; constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weightx = 1.0; constraints.gridwidth = 2; add(siteOverride, constraints); constraints.gridwidth = 1; constraints.gridy = 2; constraints.anchor = GridBagConstraints.CENTER; add(buttonCancel, constraints); constraints.gridx = 2; constraints.gridy = 2; constraints.anchor = GridBagConstraints.CENTER; add(buttonImport, constraints); setDefaultCloseOperation(DISPOSE_ON_CLOSE); pack(); setVisible(true); }