Java Code Examples for java.awt.Component#paint()

The following examples show how to use java.awt.Component#paint() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: netbeans   File: ScaleFx.java    License: Apache License 2.0 6 votes vote down vote up
private Image createCompImage(Component comp, Dimension targetSize) {
    // component won't paint if not showing anyway, so don't create
    // empty image but honestly return null 
    if (!comp.isShowing()) {
        return null;
    }
    
    Image image = comp.createImage(comp.getWidth(), comp.getHeight());
    
    /*BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration().
            createCompatibleImage(comp.getWidth(), comp.getHeight());*/
    //BufferedImage image = new BufferedImage (targetSize.width, targetSize.height, BufferedImage.TYPE_INT_RGB);
    
    Graphics2D gr2d = (Graphics2D)image.getGraphics();
    
    comp.paint(gr2d);
    
    gr2d.dispose();
    
    return image;
}
 
Example 2
Source Project: osp   File: SnapshotTool.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Constructor ComponentImage
 * @param comp
 */
public ComponentImage(Component comp) {
  c = comp;
  if(comp instanceof JFrame) {
    comp = ((JFrame) comp).getContentPane();
  } else if(comp instanceof JDialog) {
    comp = ((JDialog) comp).getContentPane();
  }
  image = new BufferedImage(comp.getWidth(), comp.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
  if(comp instanceof Renderable) {
    image = ((Renderable) comp).render(image);
  } else {
    java.awt.Graphics g = image.getGraphics();
    comp.paint(g);
    g.dispose();
  }
}
 
Example 3
private static Icon createMenuIcon(Icon icon, Component decorator) {
    int h = menuIconSize();
    int w = UIUtils.isAquaLookAndFeel() ? h + 4 : h;

    BufferedImage i = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    Graphics g = i.getGraphics();

    if (decorator != null) {
        decorator.setSize(w, h);
        decorator.paint(g);
    }

    icon.paintIcon(null, g, (w - icon.getIconWidth()) / 2, (h - icon.getIconHeight()) / 2);
    g.dispose();

    return new ImageIcon(i);
}
 
Example 4
Source Project: ghidra   File: AbstractDockingTest.java    License: Apache License 2.0 5 votes vote down vote up
private static Image doCreateRenderedImage(Component c) {
	Rectangle r = c.getBounds();
	BufferedImage bufferedImage =
		new BufferedImage(r.width, r.height, BufferedImage.TYPE_INT_ARGB);
	Graphics graphics = bufferedImage.getGraphics();
	c.paint(graphics);
	graphics.dispose();
	return bufferedImage;
}
 
Example 5
public static Image snapshot(Component component) {
   Image img = component.createImage(component.getSize().width,
                          component.getSize().height);
   if (img != null) {
   Graphics igc = img.getGraphics();
   //Gotta set the clip, or else paint throws an exception
   igc.setClip(0, 0, component.getSize().width,
      component.getSize().height);
      component.paint(igc);
   }
   return img;
}
 
Example 6
Source Project: wandora   File: Print.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void print(Component component) {
    if(component != null) {
        BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = image.createGraphics();
        if(component instanceof JComponent) {
            ((JComponent) component).setDoubleBuffered(false);
        }
        component.paint(g);
        if(component instanceof JComponent) {
            ((JComponent) component).setDoubleBuffered(true);
        }
        printImage(image);
    }
}
 
Example 7
Source Project: netbeans   File: SheetTable.java    License: Apache License 2.0 5 votes vote down vote up
/** Workaround for excessive paints by SwingUtilities.paintComponent() */
private void paintComponent(Graphics g, Component c, int x, int y, int w, int h) {
    c.setBounds(x, y, w, h);
    g.translate(x, y);
    c.paint(g);
    g.translate(-x, -y);
    c.setBounds(-w, -h, 0, 0);
}
 
Example 8
public static BufferedImage drawComponent(Component c)
{
  validateComponent(c);
  BufferedImage image = new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB);
  Graphics g = image.createGraphics();
  c.paint(g);
  g.dispose();
  return image;
}
 
Example 9
@Override
public void mousePressed (MouseEvent e)
{
    Component c = e.getComponent();

    // Copy the component current appearance
    image = new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB);

    Graphics g = image.getGraphics();
    c.paint(g);

    // Standard processing
    super.mousePressed(e);
}
 
Example 10
/**
 * Calls <code>Component.paint(Graphics)</code> with given Graphics.
 */
protected void paintComponent(Component comp, Graphics g) {
    if (comp != null) {
        comp.paint(g);
    }
}
 
Example 11
/**
 * Calls <code>Component.paint(Graphics)</code> with given Graphics.
 */
protected void paintComponent(Component comp, Graphics g) {
    if (comp != null) {
        comp.paint(g);
    }
}
 
Example 12
/**
 * Calls <code>Component.paint(Graphics)</code> with given Graphics.
 */
protected void paintComponent(Component comp, Graphics g) {
    if (comp != null) {
        comp.paint(g);
    }
}
 
Example 13
private static BufferedImage getScreenshotImage(final Component container) {
    final Rectangle rec = container.getBounds();
    final BufferedImage capture = getCompatibleBufferedImage(rec.width, rec.height);
    container.paint(capture.getGraphics());
    return capture;
}
 
Example 14
Source Project: astor   File: ExampleUtils.java    License: GNU General Public License v2.0 4 votes vote down vote up
private static BufferedImage getScreenShot(Component component) {
    BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB);
    // call the Component's paint method, using the Graphics object of the image.
    component.paint(image.getGraphics());
    return image;
}
 
Example 15
/**
 * Calls {@code Component.paint(Graphics)} with given Graphics.
 */
protected void paintComponent(Component comp, Graphics g) {
    if (comp != null) {
        comp.paint(g);
    }
}
 
Example 16
private void paintFrameToBufferedImage(Component component) {
   component.paint(bi.getGraphics());
}
 
Example 17
/**
 * Calls <code>Component.paint(Graphics)</code> with given Graphics.
 */
protected void paintComponent(Component comp, Graphics g) {
    if (comp != null) {
        comp.paint(g);
    }
}
 
Example 18
Source Project: astor   File: ExampleUtils.java    License: GNU General Public License v2.0 4 votes vote down vote up
private static BufferedImage getScreenShot(Component component) {
    BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB);
    // call the Component's paint method, using the Graphics object of the image.
    component.paint(image.getGraphics());
    return image;
}
 
Example 19
/**
 * Calls <code>Component.paint(Graphics)</code> with given Graphics.
 */
protected void paintComponent(Component comp, Graphics g) {
    if (comp != null) {
        comp.paint(g);
    }
}
 
Example 20
Source Project: hipparchus   File: ExampleUtils.java    License: Apache License 2.0 4 votes vote down vote up
private static BufferedImage getScreenShot(Component component) {
    BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB);
    // call the Component's paint method, using the Graphics object of the image.
    component.paint(image.getGraphics());
    return image;
}