本文介绍了FileChooser.showOpenDialog在框架顶部显示默认的Java图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在我的swing应用程序中创建了FileChooser.当我单击open时,打开的对话框将在框架顶部显示默认图像(java),而不是为我的JFrame设置的自定义图像.
I have created a FileChooser in my swing application. when I click on open ,the open dialog box showing default image(java) on top of the frame instead of custom image which i was set for my JFrame.
Sample Code:
JFileChooser filec=new JFileChooser();
int fileval=filec.showOpenDialog(myjframe);
我发现它有时运行良好.请为此提供帮助.
I found some times it is working fine.please help me on this.
推荐答案
在此SSCCE中似乎可以可靠地工作.此代码在您所在的位置是否可以可靠地工作?
It seems to work reliably here with this SSCCE. Does this code work reliably where you are?
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
public class FileChooserIcon {
public static void main(String[] args) {
Runnable r = new Runnable() {
@Override
public void run() {
Image image =
new BufferedImage(32,32,BufferedImage.TYPE_INT_RGB);
JFrame f = new JFrame("Demo");
f.setIconImage(image);
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// See http://stackoverflow.com/a/7143398/418556 for demo.
f.setLocationByPlatform(true);
f.pack();
f.setSize(600,400);
f.setVisible(true);
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(f);
}
};
SwingUtilities.invokeLater(r);
}
}
这篇关于FileChooser.showOpenDialog在框架顶部显示默认的Java图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!