下面列出了javax.swing.JComponent#getTreeLock ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* @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;
}
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();
}
public static void setSubcomponentsNotOpaque(JComponent j) {
synchronized(j.getTreeLock()) {
iterateOverOpaqueLayersComponents(j);
}
}