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

The following examples show how to use javax.swing.JComponent#getTreeLock() . 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 File: UIUtilities.java    From gcs with 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 File: AnimatedLayout.java    From pumpernickel with 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
Source File: FreeColDialog.java    From freecol with GNU General Public License v2.0 4 votes vote down vote up
public static void setSubcomponentsNotOpaque(JComponent j) {
    synchronized(j.getTreeLock()) {
        iterateOverOpaqueLayersComponents(j);
    }
}