/** * Use this method to create a screenshot of the JFrame object argFrame. * * Author(s): * Dejan Lekic * License: * Public Domain * * @param argFrame JFrame you want to make screenshot of. */ public static final void makeScreenshot(JFrame argFrame) { Rectangle rec = argFrame.getBounds(); BufferedImage bufferedImage = new BufferedImage(rec.width, rec.height, BufferedImage.TYPE_INT_ARGB); argFrame.paint(bufferedImage.getGraphics()); try { // Create temp file. File temp = File.createTempFile("screenshot", ".png"); // Use the ImageIO API to write the bufferedImage to a temporary file ImageIO.write(bufferedImage, "png", temp); // Delete temp file when program exits. temp.deleteOnExit(); } catch (IOException ioe) { LOGGER.debug(ioe.toString()); } // catch } // makeScreenshot method
/** * Creates new form About * * @param parent * parent */ public About(JFrame parent) { super(parent, true); initComponents(); pack(); Rectangle parentBounds = parent.getBounds(); Dimension size = getSize(); // Center in the parent int x = Math.max(0, parentBounds.x + (parentBounds.width - size.width) / 2); int y = Math.max(0, parentBounds.y + (parentBounds.height - size.height) / 2); setLocation(new Point(x, y)); }
/** * Gets the bounds of the applications mainframe. * * @return Rectangle Object. */ public Rectangle getBounds() { return frame.getBounds(); }
/** * Gets the bounds of the applications mainframe. * * @return Rectangle Object. */ public Rectangle getBounds() { return frame.getBounds(); }
public Rectangle getBounds() { return frame.getBounds(); }
private void update() { f.getBounds( r ); lb.setText( "L " + r.x + ", T " + r.y + ", R " + (r.x + r.width) + ", B " + (r.y + r.height) + ", W " + r.width + ", H " + r.height ); }
@Override public void componentShown(final ComponentEvent e) { look.reLayout(appWindow.getBounds()); }
public void captureFrame(JFrame frame, String fileName) throws Exception { BufferedImage image = new Robot().createScreenCapture(frame.getBounds()); ImageIO.write(image, "png", new File(fileName)); }
@Override public void componentResized(final ComponentEvent e) { look.reLayout(appWindow.getBounds()); }
public static void main(String args[]) throws Exception { final JFrame oldFrame = new JFrame("Test"); oldFrame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { JFrame newFrame = new JFrame("Test"); newFrame.setBounds(oldFrame.getBounds()); newFrame.setVisible(true); } }); oldFrame.setSize(400, 300); oldFrame.setVisible(true); }
public static final void makeScreenshot(JFrame f) { Rectangle rec = f.getBounds(); BufferedImage bufferedImage = new BufferedImage(rec.width, rec.height, BufferedImage.TYPE_INT_ARGB); f.paint(bufferedImage.getGraphics()); try { // Create temp file File temp = File.createTempFile("screenshot", ".png"); ImageIO.write(bufferedImage, "png", temp); // Delete temp file on exit temp.deleteOnExit(); } catch (IOException ioe) { LOGGER.debug(ioe.toString()); } }
public boolean isVisibleOnScreen() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); Rectangle fr = (useDesktop?jInternalFrame.getBounds():jFrame.getBounds()); for (GraphicsDevice g : gs) { GraphicsConfiguration dc = g.getDefaultConfiguration(); if (fr.intersects(dc.getBounds())) { return true; } } return false; }
private void initApplicationPosition() { Rectangle sizeAndPosition = applicationSettings.getSizeAndPosition(); int xPos = sizeAndPosition.x; int yPos = sizeAndPosition.y; if (xPos <= 0 || yPos <= 0) { frame.setLocationRelativeTo(null); } else { frame.setLocation(new Point(xPos, yPos)); } if (!SwingUtilities.isRectangleContainingRectangle(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()), frame.getBounds())) { jQuickStart.setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT)); frame.setLocationRelativeTo(null); } }
private void applyFrameSize(final JFrame frame, int win_x, int win_y) { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); Rectangle r = env.getMaximumWindowBounds(); for(GraphicsDevice device : env.getScreenDevices()) { if(!device.equals(env.getDefaultScreenDevice())) { Rectangle bounds = device.getDefaultConfiguration().getBounds(); r.add(bounds); } } frame.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault())); frame.setPreferredSize(new Dimension(Math.min(r.width, frame.getBounds().width), Math.min(r.height, frame.getBounds().height))); // frame.setLocation(Math.max(r.x, frame.getBounds().x), Math.max(r.y, frame.getBounds().y)); frame.setLocation(Math.max(r.x, win_x), Math.max(r.y, win_y)); }
@Override public void windowStateChanged(WindowEvent e) { int state = e.getNewState(); if ((state & Frame.ICONIFIED) == 0) { look.reLayout(appWindow.getBounds()); } } };
void recordGeometry(TreePanel panel) { String pTitle = panel.getRootPath().toString(); pTitle = pStr2Key(pTitle); JFrame frame = panel.getFrame(); if (frame!=null) { Rectangle rect=frame.getBounds(); String xCoord = (new Integer(rect.x)).toString(); String yCoord = (new Integer(rect.y)).toString(); String width = (new Integer(rect.width)).toString(); String height = (new Integer(rect.height)).toString(); if (pTitle.equals("Control_Panel")) pTitle = "Control_Panel.@Main"; String geometry = xCoord+" "+yCoord+" "+width+" "+height; if (IJ.debugMode) IJ.log("CP.recordGeometry: "+pTitle+" "+geometry); Prefs.set(pTitle, geometry); } }
protected void centerCursor() { try { Robot robot = new Robot(); Rectangle bounds = frame.getBounds(); robot.mouseMove(bounds.x+bounds.width/2, bounds.y+bounds.height/2); } catch (AWTException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
private void maybeSaveFrameSize(ComponentEvent e) { if (e.getComponent() instanceof JFrame) { JFrame f = (JFrame) e.getComponent(); if ((f.getExtendedState() & Frame.MAXIMIZED_BOTH) == 0) { SwingHelper.putWindowNormalBounds(f, f.getBounds()); } } }
/** * Saves the frame state to the object store and */ void shutDown() { try { ObjectStore os = (ObjectStore) JETARegistry.lookup(ComponentNames.APPLICATION_STATE_STORE); FrameState fstate; if (m_properties_frame == null) fstate = new FrameState(); else fstate = new FrameState(m_properties_frame.getBounds()); os.store(ID_PROPERTIES_FRAME_STATE, fstate); } catch (Exception e) { // ignore } }
private void maybeSaveFrameSize(ComponentEvent e) { if (e.getComponent() instanceof JFrame) { JFrame f = (JFrame)e.getComponent(); if ((f.getExtendedState() & Frame.MAXIMIZED_BOTH) == 0) { String clientPropertyKey = "WindowState.normalBounds"; f.getRootPane().putClientProperty(clientPropertyKey, f.getBounds()); } } } public void componentResized(ComponentEvent e) { maybeSaveFrameSize(e); }