| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
Human Touch Medienproduktion GmbHAnd how would I do that?
A tree node is eventually a Jlabel....
TreeCellRenderer tcr = tree.getCellRenderer();
JLabel dragLabel = (JLabel)tcr.getTreeCellRendererComponent(tree,
node, true, true, node.isLeaf(), selRow, true);
Image dragImage = DragImage.createDragImage(dragLabel);
Use this static method, albeit quite chopped up from the e-mail...
public static Image createDragImage(JLabel label) {
Dimension d = label.getSize();
BufferedImage ghostImage = new BufferedImage(d.width, d.height,
BufferedImage.TYPE_INT_ARGB_PRE);
Graphics2D g2 = ghostImage.createGraphics();
// Ask the cell renderer to paint itself into the BufferedImage
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0.5f));
label.paint(g2);
// Now paint a gradient UNDER the ghosted JLabel text (but not under
// the icon if any)
// Note: this will need tweaking if your icon is not positioned to
// the left of the text
Icon icon = label.getIcon();
int nStartOfText = (icon == null) ? 0 : icon.getIconWidth() +
label.getIconTextGap();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OVER,
0.5f));
g2.setPaint(new GradientPaint(nStartOfText, 0,
SystemColor.controlShadow, ghostImage.getWidth(),
0, new Color(255,255,255,0)));
g2.fillRect(nStartOfText, 0, ghostImage.getWidth(),
ghostImage.getHeight());
g2.dispose();
return ghostImage;
}
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.