0

I have a JavaFX tableview in which I'm listing files and their properties, including the ICON of the file. My problem is that a part of the icon is missing.

I don't know how to describe it completely so I included an image below.

enter image description here

My tableview is to the right and windows explorer is to the left.

Here is the code:

@Override
public void updateItem(ImageIcon imageIcon, boolean empty){
    if (imageIcon != null){
        // I have tried adding minimum width and height too
        HBox box= new HBox();

        // JavaFX scene imageview
        ImageView imageView = new ImageView();
        // Have tried with and without setFitHeight
        imageView.setFitHeight(16);
        imageView.setFitWidth(16);

        // This line prints: 16 16
        System.out.println(imageIcon.getIconWidth() + " " + imageIcon.getIconHeight());

        // Create BufferedImage of the imageicon
        BufferedImage bi = new BufferedImage(
                imageIcon.getIconWidth(),
                imageIcon.getIconHeight(),
                BufferedImage.TYPE_INT_ARGB);
        Graphics g = bi.createGraphics();

        imageIcon.paintIcon(null, g, 0, 0);
        g.dispose();

        // BufferedImage to fxImage
        Image fxImage = SwingFXUtils.toFXImage(bi, null);

        imageView.setImage(fxImage);

        box.getChildren().addAll(imageView);
        setGraphic(box);
    }
}

Thanks.

UPDATE

I have google around some more and i copied an example directly and pasted into a new project, and the same thing happened with the icons. In the example, the user was probably using windows 7 by judging the look of the icons, so maybe this is just the way it looks in windows 8. It was the code in the answer at the bottom with a picture: www.stackoverflow.com/questions/28034432/

Johan
  • 475
  • 4
  • 17
  • Why would you use Swing ImageIcon in JavaFX? – Eugene Ryzhikov Jun 08 '15 at 17:24
  • Hi! Because I am getting the icon with file systemview so I thought this was the right way – Johan Jun 08 '15 at 17:26
  • What is file system view? Do you mean FileChooser? – Eugene Ryzhikov Jun 08 '15 at 17:55
  • @eugener No I am getting the icon like this: FileSystemView view = FileSystemView.getFileSystemView(); and theh i call this method which returns an icon which I cast to an imageIcon , (imageIcon = (ImageIcon) view.getSystemIcon(file)) – Johan Jun 08 '15 at 17:57
  • Can you provide a [MCVE](http://stackoverflow.com/help/mcve) with focus on **complete**? – Roland Jun 09 '15 at 03:22
  • @Roland I have google around some more and i copied an example directly and pasted into a new project, and the same thing happened with the icons. In the example, the user was probably using windows 7 by judging the look of the icons, so maybe this is just the way it looks in windows 8. It was the code in the answer at the bottom with a picture: http://stackoverflow.com/questions/28034432/javafx-file-listview-with-icon-and-file-name – Johan Jun 09 '15 at 16:33

0 Answers0