【发布时间】:2013-06-04 00:17:14
【问题描述】:
我想要的是在用户从文件选择器中选择图像后在标签中显示图像,我遵循了很多教程,其中之一是 https://netbeans.org/kb/docs/java/gui-image-display.html 它在我硬编码图像名称时起作用,但是我真正需要的是显示用户从文件选择器中选择的内容。我试过这个 诠释 retV; 文件文件=null;
if (fc== null)
fc=new JFileChooser();
fc.addChoosableFileFilter(new ImageFilter());
fc.setAcceptAllFileFilterUsed(false);
retV =fc.showOpenDialog(GUI.this);
if (retV == JFileChooser.APPROVE_OPTION)
file = fc.getSelectedFile();
infoText.append("-The image : "+file.getAbsolutePath()+"\nwill be conveted to PNG format becuase it's a lossless\n compression.\n");
ImageIcon icon= new ImageIcon(file.getAbsolutePath());
img1=new JLabel(icon);
但它没有用。
非常感谢任何帮助
【问题讨论】:
-
file.getAbsolutePath() 显示什么?
-
你尝试调试了吗?并确保可见 put img1.setVisible(true)
-
@John an image jpeg image
标签: java image swing jlabel jfilechooser