Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: DnD JTree



Hello,

thank you very much. This was exactly the right hint I needed.
I only have problems painting the JLabel.
Any idea what could cause the "label.paint(g2);" not to work?

I modified your code to just paint a transparent rectangle with a surrounding line.
For anyone who is interested:

I obtain the Dimension just the way you did from the TreeCellRenderer JLabel and hand it over to:

public static Image createDragOutline(Dimension d) {
BufferedImage ghostImage = new BufferedImage(d.width, d.height,BufferedImage.TYPE_INT_ARGB_PRE);
Graphics2D g2 = ghostImage.createGraphics();

g2.setColor(new Color(255,190,0,100));
g2.fillRect(0,0,ghostImage.getWidth(),ghostImage.getHeight());
g2.setColor(new Color(255,190,0));
g2.drawRect(0,0,ghostImage.getWidth() - 1,ghostImage.getHeight() - 1);
g2.dispose();

return ghostImage;
}

Many thanx. Regards,

Alex

Am Dienstag, 08.07.03, um 21:57 Uhr (Europe/Berlin) schrieb Will Gilbert:

And 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;

}



Human Touch Medienproduktion GmbH
WebJazz Internet Suite
Alexander Lohse
Am See 1
17440 Klein Jasedow

Tel: (038374) 75211
Fax: (038374) 75223
e-mail: email@hidden
web: http://www.webjazz.de
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.



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.