Sunday 15 January 2012

Java/JavaFX: Set Swing Icon for JavaFX label -



Java/JavaFX: Set Swing Icon for JavaFX label -

i'm trying read thumbnail (icon; 32x32px) file (.ico/.exe) , set javafx label.

my first try:

public icon getlargeicon(string exefile) { if (exefile != null) { file file = new file(exefile); seek { shellfolder sf = shellfolder.getshellfolder(file); homecoming new imageicon(sf.geticon(true), sf.getfoldertype()); } grab (filenotfoundexception e) { e.printstacktrace(); } } homecoming null; }

after i'm doing this:

icon largeicon = getlargeicon(file.getabsolutepath()); imageicon swingimageicon = (imageicon) largeicon; java.awt.image awtimage = swingimageicon.getimage(); image fximage = javafx.scene.image.image.impl_fromplatformimage(awtimage); lblappiconvalue.setgraphic(new imageview(fximage));

i've searched trough several sites , found this, gives me exception: java.lang.unsupportedoperationexception: unsupported class loadplatformimage

my sec try:

url url = file.touri().tourl(); image image = new image(url.tostring()); lblappiconvalue.setgraphic(new imageview(image));

also not working ...

my question: how can set javax.swing.icon javafx label? possible? if it's not possible, how can read thumbnail file , set icon/graphic javafx label?

thanks!

never utilize impl_ methods: these not part of public api.

to convert awt image fx image, swingfxutils class in javafx.embed.swing has tofximage(...) method converts bufferedimage javafx image. it's not clear whether image have icon bufferedimage, you'll need couple of steps create work:

bufferedimage bimg ; if (awtimage instanceof bufferedimage) { bimg = (bufferedimage) awtimage ; } else { bimg = new bufferedimage(awtimage.getwidth(null), awtimage.getheight(null), bufferedimage.type_int_argb); graphics2d graphics = bimg.creategraphics(); graphics.drawimage(awtimage, 0, 0, null); graphics.dispose(); } image fximage = swingfxutils.tofximage(bimg, null);

this inefficient approach, first creating awt image file, converting fx image, perchance via intermediate buffered image. if have access source code shellfolder class, might see how implements geticon() method , follow same process. @ point, must inputstream image data; 1 time have can pass javafx.scene.image.image constructor.

java javafx icons label

No comments:

Post a Comment