component.paint( image.getGraphics() ); // alternately use .printAll(..) return image;
/** * Paint one List cell: compute the relevant state, get the "rubber stamp" * cell renderer component, and then use the CellRendererPane to paint it. * Subclasses may want to override this method rather than paint(). * * @see #paint */ private void paintCell(Graphics g, int index) { Object value = getModel().getElementAt(index); boolean cellHasFocus = hasFocus() && (index == getSelectionModel().getLeadSelectionIndex()); boolean isSelected = getSelectionModel().isSelectedIndex(index); Component renderer = getCellRenderer().getListCellRendererComponent( this, value, index, isSelected, cellHasFocus ); renderer.setSize(fixedCellWidth, fixedCellHeight); renderer.paint(g); }
/** 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); }
protected BufferedImage getBufferedImage() { BufferedImage output = new BufferedImage(parent.getWidth(),parent.getHeight(), BufferedImage.TYPE_INT_BGR); parent.paint(output.createGraphics()); return output; } }
/** 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); }
static public BufferedImage createComponentImage(Component component) { Dimension size = component.getSize(); BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); component.paint(g2); g2.dispose(); return image; }
static public BufferedImage createImageFrom(Component component){ Dimension size = component.getPreferredSize(); if (size.width == 0 || size.height == 0){ size = component.getSize(); } BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); component.paint(g2); g2.dispose(); return image; }
static public BufferedImage createComponentImage(Component component) { Dimension size = component.getSize(); BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); component.paint(g2); g2.dispose(); return image; }
public static void writeImage(Component comp, String filename, String formatName) throws IOException { Image image = new BufferedImage( comp.getSize().width, comp.getSize().height, BufferedImage.TYPE_4BYTE_ABGR); comp.paint(image.getGraphics()); ImageIO.write((RenderedImage) image, formatName, new File(filename)); }
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; } private static void validateComponent(Component c)
void paintComp(Graphics g, Component aComp) { if(aComp != null && aComp.isVisible()) { Point lLoc = aComp.getLocation(); g.translate(lLoc.x, lLoc.y); aComp.paint(g); g.translate(-lLoc.x, -lLoc.y); } }
public static Image getDebugImage(Component component) { BufferedImage image = createImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = image.createGraphics(); graphics.setColor(Color.RED); graphics.fillRect(0, 0, component.getWidth() + 1, component.getHeight() + 1); component.paint(graphics); return image; }
@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); } }
Component applet = ...; // the applet Dimension size = applet.getSize(); BufferedImage offScreenImage = (BufferedImage) applet.createImage(size.width, size.height); Graphics2D g2 = offScreenImg.createGraphics(); g2.setBackground(applet.getBackground()); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.clearRect(0, 0, size.width, size.height); applet.paint(g2); // now you can use BufferedImage as before
@Override protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g.create(); c.setSize(new Dimension(getWidth(), getHeight())); c.paint(g2d); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.translate(1, 1); paintRectangleWithHighlightColour(g2d, getWidth() - 2, getHeight() - 2); } };
public int print(Graphics g, PageFormat pageFormat, int pageIndex) { if (pageIndex > 0) { return(NO_SUCH_PAGE); } else { Graphics2D g2d = (Graphics2D)g; g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); disableDoubleBuffering(componentToBePrinted); componentToBePrinted.paint(g2d); enableDoubleBuffering(componentToBePrinted); return(PAGE_EXISTS); } }
public int print(Graphics g, PageFormat pageFormat, int pageIndex) { if (pageIndex > 0) { return(NO_SUCH_PAGE); } else { Graphics2D g2d = (Graphics2D)g; g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); disableDoubleBuffering(componentToBePrinted); componentToBePrinted.paint(g2d); enableDoubleBuffering(componentToBePrinted); return(PAGE_EXISTS); } }
public int print(Graphics g, PageFormat pageFormat, int pageIndex) { if (pageIndex > 0) { return(NO_SUCH_PAGE); } else { Graphics2D g2d = (Graphics2D)g; g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); disableDoubleBuffering(componentToBePrinted); componentToBePrinted.paint(g2d); enableDoubleBuffering(componentToBePrinted); return(PAGE_EXISTS); } }
public void paint(Graphics g) { if (showHeavyweight) { valueComponent.setSize(getSize()); if (!isEditing) valueComponent.paint(g); } else { g.drawRect(0, 0, getWidth() - 1, getHeight() - 1); g.drawLine(0, 0, getWidth() - 1, getHeight() - 1); g.drawLine(getWidth() - 1, 0, 0, getHeight() - 1); } } };