Eu criei um programinha onde o usuario pode alterar o icone dos botões, estou usando o JFileChooser para poder selecionar os icones, eu gostaria de saber se tem como ter um preview dentro deste componente para o usuario ir olhando os icones antes de selecionar como no explorer do windows.
Caso não alguém tem alguma ideia?
JFileChooserchooser=newJFileChooser();PreviewPanepreviewPane=newPreviewPane();chooser.setAccessory(previewPane);chooser.addPropertyChangeListener(previewPane);chooser.showDialog(frame,"OK");staticclassPreviewPaneextendsJPanelimplementsPropertyChangeListener{privateJLabellabel;privateintmaxImgWidth;publicPreviewPane(){setLayout(newBorderLayout(5,5));setBorder(BorderFactory.createEmptyBorder(5,5,5,5));add(newJLabel("Preview:"),BorderLayout.NORTH);label=newJLabel();label.setBackground(Color.WHITE);label.setOpaque(true);label.setPreferredSize(newDimension(200,200));maxImgWidth=195;label.setBorder(BorderFactory.createEtchedBorder());add(label,BorderLayout.CENTER);}publicvoidpropertyChange(PropertyChangeEventevt){Iconicon=null;if(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(evt.getPropertyName())){FilenewFile=(File)evt.getNewValue();if(newFile!=null){Stringpath=newFile.getAbsolutePath();if(path.endsWith(".gif")||path.endsWith(".jpg")||path.endsWith(".png")||path.endsWith(".bmp")){try{BufferedImageimg=ImageIO.read(newFile);floatwidth=img.getWidth();floatheight=img.getHeight();floatscale=height/width;width=maxImgWidth;height=(width*scale);// height should be scaled from new width icon=newImageIcon(img.getScaledInstance(Math.max(1,(int)width),Math.max(1,(int)height),Imag.SCALE_SMOOTH));}catch(IOExceptione){// couldn't read image.}}}label.setIcon(icon);this.repaint();}}}