public static void showOnScreen( int screen, JFrame frame ) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gd = ge.getScreenDevices(); if( screen > -1 && screen < gd.length ) { frame.setLocation(gd[screen].getDefaultConfiguration().getBounds().x, frame.getY()); } else if( gd.length > 0 ) { frame.setLocation(gd[0].getDefaultConfiguration().getBounds().x, frame.getY()); } else { throw new RuntimeException( "No Screens Found" ); } }
buttonFrame.setResizable(false); buttonFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); buttonFrame.move(buttonFrame.getX(), buttonFrame.getY() + height / 2);
/** * {@inheritDoc} * <p/> * <b>NOTE:</b> If this window is casting a shadow, calling this method * might provide inaccurate results unless you take into account the margin * constants found in {@link MaterialShadow}. In order to make things easier * to handle, it is preferable to use {@link #getYLocation()}. * @deprecated use {@link #getYLocation()} instead. */ @Override @Deprecated public int getY() { return super.getY(); }
/** * Alternative method to {@link JFrame#getY()}. Use it to get the location * of this window in the desktop, excluding any margins present because of * the shadow. * @return the current y coordinate of this window's origin */ public int getYLocation() { return super.getY() + (!isShadowed() ? 0:MaterialShadow.OFFSET_TOP); }
final JFrame jFrame = new JFrame(); jFrame.getRootPane().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.VK_UNDEFINED), "moveRight"); jFrame.getRootPane().getActionMap().put("moveRight", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { jFrame.setLocation(jFrame.getX() + 5, jFrame.getY()); } }); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jFrame.setLocationRelativeTo(null); jFrame.setVisible(true);
JFrame f1 = ...; JFrame f2 = ...; f1.setLocationRelativeTo(null); f2.setLocation(new Point(f1.getX(), f2.getY() + 20));
public class Test { public static void main (String[] args) { JFrame f1 = new JFrame(); f1. setSize(100, 100); f1.setLocationRelativeTo(null); f1.setVisible(true); JFrame f2 = new JFrame(); f2.setSize(100, 100); f2.setLocation(f1.getX() + f1.getWidth(), f1.getY()); f2.setVisible(true); } }
JFrame frame = new JFrame(); frame.setLocation(100, 100); frame.setSize(500, 500); frame.setVisible(true); try { Robot robot = new Robot(); robot.mouseMove(frame.getX() + 250, frame.getY() + 250); } catch (AWTException e) { // TODO Auto-generated catch block e.printStackTrace(); }
public void setComponent(JFrame frame) { this.component = frame; activeWindowGL.setLocation(frame.getX(), frame.getY()); }
public void show(){ dialog.setPreferredSize(this.preferredSize); dialog.pack(); // center if(parentFrame != null){ int newX = parentFrame.getX() + parentFrame.getWidth()/2 - dialog.getPreferredSize().width/2; int newY = parentFrame.getY() + parentFrame.getHeight()/2 - dialog.getPreferredSize().height/2; dialog.setLocation(newX, newY); } dialog.setVisible(true); }
public void windowClosing(java.awt.event.WindowEvent evt) { int numCols = tracerTable.getColumnCount(); for (int i = 0; i < numCols; i++) uiMgr.putInt("studio/tracer_col_width/" + i, tracerTable.getColumnModel().getColumn(i).getWidth()); uiMgr.putInt("studio/tracer_win_pos_x", tracerFrame.getX()); uiMgr.putInt("studio/tracer_win_pos_y", tracerFrame.getY()); uiMgr.putInt("studio/tracer_win_pos_w", tracerFrame.getWidth()); uiMgr.putInt("studio/tracer_win_pos_h", tracerFrame.getHeight()); tracerFrame.dispose(); } });
@Override public void componentMoved(ComponentEvent e) { listFrame.setLocation(mainFrame.getX() + mainFrame.getWidth() + 4, mainFrame.getY()); }
public void windowClosing(java.awt.event.WindowEvent evt) { int numCols = conflictTable.getColumnCount(); for (int i = 0; i < numCols; i++) uiMgr.putInt("studio/conflicts_col_width/" + i, conflictTable.getColumnModel().getColumn(i).getWidth()); uiMgr.putInt("studio/conflicts_win_pos_x", conflictsFrame.getX()); uiMgr.putInt("studio/conflicts_win_pos_y", conflictsFrame.getY()); uiMgr.putInt("studio/conflicts_win_pos_w", conflictsFrame.getWidth()); uiMgr.putInt("studio/conflicts_win_pos_h", conflictsFrame.getHeight()); conflictsFrame.dispose(); } });
public void windowClosing(java.awt.event.WindowEvent evt) { int numCols = breaksTable.getColumnCount(); for (int i = 0; i < numCols; i++) uiMgr.putInt("studio/breaks_col_width/" + i, breaksTable.getColumnModel().getColumn(i).getWidth()); uiMgr.putInt("studio/breaks_win_pos_x", breakpointsFrame.getX()); uiMgr.putInt("studio/breaks_win_pos_y", breakpointsFrame.getY()); uiMgr.putInt("studio/breaks_win_pos_w", breakpointsFrame.getWidth()); uiMgr.putInt("studio/breaks_win_pos_h", breakpointsFrame.getHeight()); breakpointsFrame.dispose(); } });
public void windowClosing(java.awt.event.WindowEvent evt) { uiMgr.putInt("studio/uicomps_win_pos_x", uiCompsFrame.getX()); uiMgr.putInt("studio/uicomps_win_pos_y", uiCompsFrame.getY()); uiMgr.putInt("studio/uicomps_win_pos_w", uiCompsFrame.getWidth()); uiMgr.putInt("studio/uicomps_win_pos_h", uiCompsFrame.getHeight()); uiCompsFrame.dispose(); } });
public void windowClosing(java.awt.event.WindowEvent evt) { uiMgr.putInt("studio/diff_win_pos_x", diffFrame.getX()); uiMgr.putInt("studio/diff_win_pos_y", diffFrame.getY()); uiMgr.putInt("studio/diff_win_pos_w", diffFrame.getWidth()); uiMgr.putInt("studio/diff_win_pos_h", diffFrame.getHeight()); diffFrame.dispose(); } });
public void windowClosing(java.awt.event.WindowEvent evt) { // Ensure the debugger isn't paused/stepping resumeExecution(); uiMgr.putInt("studio_win_pos_x", myFrame.getX()); uiMgr.putInt("studio_win_pos_y", myFrame.getY()); uiMgr.putInt("studio_win_pos_w", myFrame.getWidth()); uiMgr.putInt("studio_win_pos_h", myFrame.getHeight()); myFrame.dispose(); } });
@Override public void saveProperties() { if(mapViewWindows == null) return; saveSplitPanePosition(); if (frame.isResizable()) { final int winState = frame.getExtendedState() & ~Frame.ICONIFIED; if (JFrame.MAXIMIZED_BOTH != (winState & JFrame.MAXIMIZED_BOTH)) { resourceController.setProperty("appwindow_x", String.valueOf(frame.getX())); resourceController.setProperty("appwindow_y", String.valueOf(frame.getY())); resourceController.setProperty("appwindow_width", String.valueOf(frame.getWidth())); resourceController.setProperty("appwindow_height", String.valueOf(frame.getHeight())); } resourceController.setProperty("appwindow_state", String.valueOf(winState)); } mapViewWindows.saveLayout(); resourceController.getLastOpenedList().saveProperties(); }
@Override public void componentResized(ComponentEvent e) { listFrame.setLocation(mainFrame.getX() + mainFrame.getWidth() + 4, mainFrame.getY()); listFrame.setSize(listFrame.getWidth(), mainFrame.getHeight()); }
/** * Sets the dialog position in the centre of the application window. * * @param dialog the dialog to centre */ public void centreDialog(JDialog dialog) { if ((frame != null) && (dialog != null)) { final int x = frame.getX() + (frame.getWidth() - dialog.getWidth()) / 2; final int y = frame.getY() + (frame.getHeight() - dialog.getHeight()) / 2; dialog.setLocation(x, y); } } }