List of usage examples for java.awt Rectangle Rectangle
public Rectangle(Dimension d)
From source file:Main.java
public static void main(String[] args) throws Exception { Robot robot = new Robot(); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); BufferedImage image = robot.createScreenCapture(new Rectangle(d)); BufferedImage sub = image.getSubimage(0, 0, 400, 400); File f = new File("SubImage.png"); ImageIO.write(sub, "png", f); final ImageIcon im = new ImageIcon(f.toURI().toURL()); Runnable r = new Runnable() { @Override// ww w . ja v a2s . c o m public void run() { JOptionPane.showMessageDialog(null, new JLabel(im)); } }; SwingUtilities.invokeLater(r); }
From source file:Capture.java
public static void main(String[] args) { JFrame capture = new JFrame(); capture.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Toolkit kit = Toolkit.getDefaultToolkit(); final Dimension d = kit.getScreenSize(); capture.setSize(d);/*from ww w .j av a2s.c o m*/ Rectangle rect = new Rectangle(d); try { Robot robot = new Robot(); final BufferedImage image = robot.createScreenCapture(rect); image.flush(); JPanel panel = new JPanel() { public void paintComponent(Graphics g) { g.drawImage(image, 0, 0, d.width, d.height, this); } }; panel.setOpaque(false); panel.prepareImage(image, panel); panel.repaint(); capture.getContentPane().add(panel); } catch (Exception e) { e.printStackTrace(); } capture.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { Robot robot = new Robot(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); BufferedImage screen = robot.createScreenCapture(new Rectangle(screenSize)); new ScreenCaptureRectangle(screen); }
From source file:Main.java
public static void scroll(JTable table, int row) { table.scrollRectToVisible(new Rectangle(table.getCellRect(row, 0, true))); }
From source file:Main.java
public static void centerWithinScreen(final Window wind) { if (wind == null) { return;//w w w. j a va 2 s. c o m } final Toolkit toolKit = Toolkit.getDefaultToolkit(); final Rectangle rcScreen = new Rectangle(toolKit.getScreenSize()); final Dimension windSize = wind.getSize(); final Dimension parentSize = new Dimension(rcScreen.width, rcScreen.height); if (windSize.height > parentSize.height) { windSize.height = parentSize.height; } if (windSize.width > parentSize.width) { windSize.width = parentSize.width; } center(wind, rcScreen); }
From source file:Main.java
public static boolean isCellVisible(JTable table, int rowIndex, int vColIndex) { if (!(table.getParent() instanceof JViewport)) { return false; }//from w w w . j a v a 2 s .c om JViewport viewport = (JViewport) table.getParent(); Rectangle rect = table.getCellRect(rowIndex, vColIndex, true); Point pt = viewport.getViewPosition(); rect.setLocation(rect.x - pt.x, rect.y - pt.y); return new Rectangle(viewport.getExtentSize()).contains(rect); }
From source file:Main.java
/** * Center the given window within the screen boundaries. * * @param window the window to be centered. *///from w w w . j a v a 2 s . c o m public static void centerWindow(Window window) { Rectangle bounds; try { bounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().getBounds(); } catch (Throwable t) { Toolkit tk = window.getToolkit(); Dimension ss = tk.getScreenSize(); bounds = new Rectangle(ss); } int width = window.getWidth(), height = window.getHeight(); window.setBounds(bounds.x + (bounds.width - width) / 2, bounds.y + (bounds.height - height) / 2, width, height); }
From source file:Main.java
/** * Returns the screen bounds for a component location (or screen location if component null). *//*from w w w. j av a2 s . co m*/ public static Rectangle getScreenBounds(Component aComp, int anX, int aY, boolean doInset) { GraphicsConfiguration gc = getGraphicsConfiguration(aComp, anX, aY); Rectangle rect = gc != null ? gc.getBounds() : new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); Insets ins = doInset && gc != null ? Toolkit.getDefaultToolkit().getScreenInsets(gc) : null; if (ins != null) { int lt = ins.left, rt = ins.right, tp = ins.top, bt = ins.bottom; rect.setBounds(rect.x + lt, rect.y + tp, rect.width - lt - rt, rect.height - tp - bt); } return rect; }
From source file:Java2DUtils.java
@SuppressWarnings("unchecked") public static void setClip(Graphics g, Rectangle clipBounds) { Rectangle currentClipBounds;/*from w ww. ja v a2s .c om*/ clipBounds = new Rectangle(clipBounds); clipBounds.width += 1; clipBounds.height += 1; currentClipBounds = g.getClipBounds(); if (currentClipBounds != null) { clipBounds = clipBounds.intersection(g.getClipBounds()); } clipBoundsStack.push(currentClipBounds); g.setClip(clipBounds); }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Rectangle r = new Rectangle(new Dimension(10, 10)); g2.fill(r);//w ww . j av a 2 s . c om System.out.println(r.isEmpty()); }