javax.swing.JComponent#paint ( )源码实例Demo

下面列出了javax.swing.JComponent#paint ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: gcs   文件: UIUtilities.java
/**
 * @param component The component to generate an image of.
 * @return The newly created image.
 */
public static Img getImage(JComponent component) {
    Img offscreen = null;
    synchronized (component.getTreeLock()) {
        Graphics2D gc = null;
        try {
            Rectangle bounds = component.getVisibleRect();
            offscreen = Img.create(component.getGraphicsConfiguration(), bounds.width, bounds.height, Transparency.TRANSLUCENT);
            gc = offscreen.getGraphics();
            gc.translate(-bounds.x, -bounds.y);
            component.paint(gc);
        } catch (Exception exception) {
            Log.error(exception);
        } finally {
            if (gc != null) {
                gc.dispose();
            }
        }
    }
    return offscreen;
}
 
源代码2 项目: jdk8u_jdk   文件: bug8032667_image_diff.java
static BufferedImage getImage(JComponent component, int scale, int width, int height) {
    final BufferedImage image = new BufferedImage(
            scale * width, scale * height, BufferedImage.TYPE_INT_ARGB);
    final Graphics g = image.getGraphics();
    ((Graphics2D) g).scale(scale, scale);
    component.paint(g);
    g.dispose();
    return image;
}
 
源代码3 项目: dragonwell8_jdk   文件: bug8032667.java
static Image getImage(JComponent component) {
    final BufferedImage image = new BufferedImage(
            scaledWidth, scaledHeight, BufferedImage.TYPE_INT_ARGB);
    final Graphics g = image.getGraphics();
    ((Graphics2D) g).scale(scale, scale);
    component.paint(g);
    g.dispose();

    return image;
}
 
源代码4 项目: TencentKona-8   文件: bug8032667_image_diff.java
static BufferedImage getImage(JComponent component, int scale, int width, int height) {
    final BufferedImage image = new BufferedImage(
            scale * width, scale * height, BufferedImage.TYPE_INT_ARGB);
    final Graphics g = image.getGraphics();
    ((Graphics2D) g).scale(scale, scale);
    component.paint(g);
    g.dispose();
    return image;
}
 
源代码5 项目: TencentKona-8   文件: bug8032667.java
static Image getImage(JComponent component) {
    final BufferedImage image = new BufferedImage(
            scaledWidth, scaledHeight, BufferedImage.TYPE_INT_ARGB);
    final Graphics g = image.getGraphics();
    ((Graphics2D) g).scale(scale, scale);
    component.paint(g);
    g.dispose();

    return image;
}
 
源代码6 项目: jdk8u60   文件: bug8032667_image_diff.java
static BufferedImage getImage(JComponent component, int scale, int width, int height) {
    final BufferedImage image = new BufferedImage(
            scale * width, scale * height, BufferedImage.TYPE_INT_ARGB);
    final Graphics g = image.getGraphics();
    ((Graphics2D) g).scale(scale, scale);
    component.paint(g);
    g.dispose();
    return image;
}
 
源代码7 项目: jdk8u-jdk   文件: bug8032667.java
static Image getImage(JComponent component) {
    final BufferedImage image = new BufferedImage(
            scaledWidth, scaledHeight, BufferedImage.TYPE_INT_ARGB);
    final Graphics g = image.getGraphics();
    ((Graphics2D) g).scale(scale, scale);
    component.paint(g);
    g.dispose();

    return image;
}
 
源代码8 项目: openjdk-jdk8u   文件: bug8032667_image_diff.java
static BufferedImage getImage(JComponent component, int scale, int width, int height) {
    final BufferedImage image = new BufferedImage(
            scale * width, scale * height, BufferedImage.TYPE_INT_ARGB);
    final Graphics g = image.getGraphics();
    ((Graphics2D) g).scale(scale, scale);
    component.paint(g);
    g.dispose();
    return image;
}
 
源代码9 项目: openjdk-jdk8u   文件: bug8032667.java
static Image getImage(JComponent component) {
    final BufferedImage image = new BufferedImage(
            scaledWidth, scaledHeight, BufferedImage.TYPE_INT_ARGB);
    final Graphics g = image.getGraphics();
    ((Graphics2D) g).scale(scale, scale);
    component.paint(g);
    g.dispose();

    return image;
}
 
源代码10 项目: binnavi   文件: AbstractTreeTransferHandler.java
@Override
public final void dragGestureRecognized(final DragGestureEvent dge) {
  // final TreePath path = tree.getSelectionPath();
  final TreePath path = tree.getPathForLocation(dge.getDragOrigin().x, dge.getDragOrigin().y);

  if (path != null) {
    draggedNode = (DefaultMutableTreeNode) path.getLastPathComponent();
    draggedNodeParent = (DefaultMutableTreeNode) draggedNode.getParent();
    if (drawImage) {
      final Rectangle pathBounds = tree.getPathBounds(path); // getpathbounds of selectionpath
      final JComponent lbl =
          (JComponent) tree.getCellRenderer().getTreeCellRendererComponent(tree, draggedNode,
              false, tree.isExpanded(path),
              ((DefaultTreeModel) tree.getModel()).isLeaf(path.getLastPathComponent()), 0, false);// returning
                                                                                                  // the
                                                                                                  // label
      lbl.setBounds(pathBounds);// setting bounds to lbl
      image =
          new BufferedImage(lbl.getWidth(), lbl.getHeight(),
              java.awt.image.BufferedImage.TYPE_INT_ARGB_PRE);// buffered image reference passing
                                                              // the label's ht and width
      final Graphics2D graphics = image.createGraphics();// creating the graphics for buffered
                                                         // image
      graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); // Sets
                                                                                        // the
                                                                                        // Composite
                                                                                        // for the
                                                                                        // Graphics2D
                                                                                        // context
      lbl.setOpaque(false);
      lbl.paint(graphics); // painting the graphics to label
      graphics.dispose();
    }
    dragSource.startDrag(dge, DragSource.DefaultMoveNoDrop, image, new Point(0, 0),
        new TransferableNode(draggedNode), this);
  }
}
 
源代码11 项目: hottub   文件: bug8032667_image_diff.java
static BufferedImage getImage(JComponent component, int scale, int width, int height) {
    final BufferedImage image = new BufferedImage(
            scale * width, scale * height, BufferedImage.TYPE_INT_ARGB);
    final Graphics g = image.getGraphics();
    ((Graphics2D) g).scale(scale, scale);
    component.paint(g);
    g.dispose();
    return image;
}
 
源代码12 项目: jdk8u-dev-jdk   文件: bug8032667.java
static Image getImage(JComponent component) {
    final BufferedImage image = new BufferedImage(
            scaledWidth, scaledHeight, BufferedImage.TYPE_INT_ARGB);
    final Graphics g = image.getGraphics();
    ((Graphics2D) g).scale(scale, scale);
    component.paint(g);
    g.dispose();

    return image;
}
 
static BufferedImage getImage(JComponent component, int scale, int width, int height) {
    final BufferedImage image = new BufferedImage(
            scale * width, scale * height, BufferedImage.TYPE_INT_ARGB);
    final Graphics g = image.getGraphics();
    ((Graphics2D) g).scale(scale, scale);
    component.paint(g);
    g.dispose();
    return image;
}
 
源代码14 项目: jdk8u-jdk   文件: bug8032667_image_diff.java
static BufferedImage getImage(JComponent component, int scale, int width, int height) {
    final BufferedImage image = new BufferedImage(
            scale * width, scale * height, BufferedImage.TYPE_INT_ARGB);
    final Graphics g = image.getGraphics();
    ((Graphics2D) g).scale(scale, scale);
    component.paint(g);
    g.dispose();
    return image;
}
 
源代码15 项目: openjdk-jdk9   文件: bug8032667_image_diff.java
static BufferedImage getImage(JComponent component, int scale, int width, int height) {
    final BufferedImage image = new BufferedImage(
            scale * width, scale * height, BufferedImage.TYPE_INT_ARGB);
    final Graphics g = image.getGraphics();
    ((Graphics2D) g).scale(scale, scale);
    component.paint(g);
    g.dispose();
    return image;
}
 
源代码16 项目: openjdk-jdk9   文件: bug8032667.java
static Image getImage(JComponent component) {
    final BufferedImage image = new BufferedImage(
            scaledWidth, scaledHeight, BufferedImage.TYPE_INT_ARGB);
    final Graphics g = image.getGraphics();
    ((Graphics2D) g).scale(scale, scale);
    component.paint(g);
    g.dispose();

    return image;
}
 
源代码17 项目: pumpernickel   文件: MockComponent.java
/**
 * Creates a MockComponent that resembles the argument component.
 * <P>
 * Note this method will traverse c and its subcomponents and may
 * temporarily change properties of inner components: such as the focused
 * state, the visibility, etc.
 * <P>
 * The goal is of this component is not to mirror the exact state of a
 * component, but rather to provide a sample image of this component in its
 * plain, unmodified, unused state.
 * 
 * @param c
 */
public MockComponent(JComponent c) {
	Dimension preferredSize = c.getPreferredSize();
	Dimension currentSize = c.getSize();

	Dimension d = new Dimension(Math.max(preferredSize.width,
			currentSize.width), Math.max(preferredSize.height,
			currentSize.height));

	if (currentSize.width == 0 || currentSize.height == 0) {
		// if the component isn't visible yet
		c.setSize(d);
		c.doLayout();
	}

	storeState(c);

	image = new BufferedImage(d.width, d.height,
			BufferedImage.TYPE_INT_ARGB);

	Graphics2D g = image.createGraphics();
	g.setComposite(AlphaComposite.Clear);
	g.fillRect(0, 0, d.width, d.height);
	g.setComposite(AlphaComposite.SrcOver);

	c.paint(g);
	g.dispose();
	setPreferredSize(d);
	setMinimumSize(d);
	setMaximumSize(d);
	setOpaque(c.isOpaque());
	setName(c.getName());
	setToolTipText(c.getToolTipText());

	restoreState(c);
}
 
源代码18 项目: jdk8u-jdk   文件: bug8032667_image_diff.java
static BufferedImage getImage(JComponent component, int scale, int width, int height) {
    final BufferedImage image = new BufferedImage(
            scale * width, scale * height, BufferedImage.TYPE_INT_ARGB);
    final Graphics g = image.getGraphics();
    ((Graphics2D) g).scale(scale, scale);
    component.paint(g);
    g.dispose();
    return image;
}
 
源代码19 项目: jdk8u-jdk   文件: bug8032667.java
static Image getImage(JComponent component) {
    final BufferedImage image = new BufferedImage(
            scaledWidth, scaledHeight, BufferedImage.TYPE_INT_ARGB);
    final Graphics g = image.getGraphics();
    ((Graphics2D) g).scale(scale, scale);
    component.paint(g);
    g.dispose();

    return image;
}
 
源代码20 项目: jdk8u_jdk   文件: bug8032667.java
static Image getImage(JComponent component) {
    final BufferedImage image = new BufferedImage(
            scaledWidth, scaledHeight, BufferedImage.TYPE_INT_ARGB);
    final Graphics g = image.getGraphics();
    ((Graphics2D) g).scale(scale, scale);
    component.paint(g);
    g.dispose();

    return image;
}