Java Code Examples for javax.swing.JComponent.paint()

The following are Jave code examples for showing how to use paint() of the javax.swing.JComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: RendererPropertyDisplayer.java   View Source Code Vote up 6 votes
public void paintComponent(Graphics g) {
    //Hack for issue 38132 - Beans are set via TTVBridge as a package
    //private property on the parent PropertyPanel (if there is one).
    //FindBeans() will locate the beans either in the model or as a 
    //property of the PropertyPanel (if an esoteric undocumented client property
    //is set on the PropertyPanel).  RendererFactory will set the env
    //value (if there is an env) to the value of ReusablePropertyEnv.NODE
    //(a performance hack to avoid creating 1 property env for each property
    //painted each time we paint).  Cool, huh?
    reusableEnv.setNode(EditorPropertyDisplayer.findBeans(this));

    JComponent comp = getRenderer(this);
    prepareRenderer(comp);
    comp.setBounds(0, 0, getWidth(), getHeight());

    if (comp instanceof InplaceEditor) {
        Component inner = findInnermostRenderer(comp);
        SwingUtilities.paintComponent(g, comp, this, 0, 0, getWidth(), getHeight());
        removeAll();
        return;
    }

    comp.paint(g);
}
 
Example 2
Project: incubator-netbeans   File: HideableBarRenderer.java   View Source Code Vote up 6 votes
public void paint(Graphics g) {
    g.setColor(getBackground());
    g.fillRect(location.x, location.y, size.width, size.height);
    
    JComponent component = mainRenderer.getComponent();
    int componentWidth = component.getPreferredSize().width;
    int componentX = size.width - componentWidth;
    
    mainRenderer.move(location.x + componentX, location.y);
    component.setSize(componentWidth, size.height);
    component.paint(g);
    
    int freeWidth = size.width - maxRendererWidth - renderersGap();
    if (freeWidth >= MIN_BAR_WIDTH) {
        barRenderer.setSize(Math.min(freeWidth, MAX_BAR_WIDTH), size.height);
        barRenderer.move(location.x, location.y);
        barRenderer.paint(g);
    }
}
 
Example 3
Project: incubator-netbeans   File: DnDSupport.java   View Source Code Vote up 5 votes
private BufferedImage createContentImage( JComponent c, Dimension contentSize ) {
    GraphicsConfiguration cfg = GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice().getDefaultConfiguration();

    boolean opaque = c.isOpaque();
    c.setOpaque(true);
    BufferedImage res = cfg.createCompatibleImage(contentSize.width, contentSize.height);
    Graphics2D g = res.createGraphics();
    g.setColor( c.getBackground() );
    g.fillRect(0, 0, contentSize.width, contentSize.height);
    g.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f ));
    c.paint(g);
    c.setOpaque(opaque);
    return res;
}
 
Example 4
Project: rapidminer   File: PlotterAdapter.java   View Source Code Vote up 5 votes
@Override
public void render(Graphics graphics, int width, int height) {
	JComponent renderComponent = getRenderComponent();
	renderComponent.setSize(width, height);
	renderComponent.setDoubleBuffered(false);
	renderComponent.paint(graphics);
	renderComponent.setDoubleBuffered(true);
}
 
Example 5
Project: CoverageGA   File: SensorDrawUtility.java   View Source Code Vote up 5 votes
public static BufferedImage getAreaAsImage(final int w, final int h, final JComponent component) {
	final int type = BufferedImage.TYPE_INT_RGB;
	final BufferedImage image = new BufferedImage(w, h, type);
	final Graphics2D g2 = image.createGraphics();
	component.paint(g2);
	g2.dispose();
	return image;
}
 
Example 6
Project: jdk8u-jdk   File: bug8032667_image_diff.java   View Source Code Vote up 5 votes
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;
}
 
Example 7
Project: jdk8u-jdk   File: bug8032667.java   View Source Code Vote up 5 votes
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;
}
 
Example 8
Project: openjdk-jdk10   File: bug8032667_image_diff.java   View Source Code Vote up 5 votes
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;
}
 
Example 9
Project: openjdk-jdk10   File: bug8032667.java   View Source Code Vote up 5 votes
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;
}
 
Example 10
Project: openjdk-jdk10   File: TitledBorderLabelUITest.java   View Source Code Vote up 4 votes
private static void paintToImage(JComponent comp) {
    BufferedImage image = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = image.createGraphics();
    comp.paint(g);
    g.dispose();
}
 
Example 11
Project: Logisim   File: JTreeUtil.java   View Source Code Vote up 4 votes
@Override
public final void dragGestureRecognized(DragGestureEvent dge) {
	TreePath path = tree.getSelectionPath();
	if (path != null) {
		draggedNode = path.getLastPathComponent();
		if (drawImage) {
			Rectangle pathBounds = tree.getPathBounds(path); // getpathbounds
																// of
																// selectionpath
			JComponent lbl = (JComponent) tree.getCellRenderer().getTreeCellRendererComponent(tree, draggedNode,
					false, tree.isExpanded(path), 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
			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);
	}
}