Java Code Examples for javax.swing.JComponent#getTreeLock()

The following examples show how to use javax.swing.JComponent#getTreeLock() . 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: gcs   File: UIUtilities.java    License: Mozilla Public License 2.0 6 votes vote down vote up
/**
 * @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;
}
 
Example 2
Source Project: pumpernickel   File: AnimatedLayout.java    License: MIT License 5 votes vote down vote up
protected void layoutContainerImmediately(JComponent parent) {
	synchronized (parent.getTreeLock()) {
		Map<JComponent, Rectangle> destMap = getDestinationMap(parent);
		for (Entry<JComponent, Rectangle> entry : destMap.entrySet()) {
			entry.getKey().setBounds(entry.getValue());
		}
	}
	parent.repaint();
}
 
Example 3
public static void setSubcomponentsNotOpaque(JComponent j) {
    synchronized(j.getTreeLock()) {
        iterateOverOpaqueLayersComponents(j);
    }
}