如何改变JFileChooser文件选择对话框左上角的图标和字体大小?

解决方案 »

  1.   

    JFileChooser左上角的图标与其放置的Frame的图标有关,如果你将放在一个JFrame上,它的图标将与JFrame的图标一致。至于字体,我在用setFont(font)尝试的时候不管用什么字体都不能达到效果,原因不明。继续研究中...
      

  2.   

    // 是你自己的gif 替换 s2t.gif
    import java.awt.BorderLayout;
    import java.awt.Font;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.util.Enumeration;
    import javax.swing.JButton;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.UIManager;
    import javax.swing.plaf.FontUIResource;
    import com.swtdesigner.SwingResourceManager;public class JFileChooserTest extends JFrame
    {
    /**
     * Launch the application
     * 
     * @param args
     */
    public static void main(String args[])
    {
    try
    {
    JFileChooserTest frame = new JFileChooserTest();
    frame.setVisible(true);
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }
    } /**
     * 设置字体。
     * 
     * @param f
     */
    private void setUIFont(Font f)
    {
    Enumeration keys = UIManager.getDefaults().keys();
    while (keys.hasMoreElements())
    {
    Object key = keys.nextElement();
    Object value = UIManager.get(key);
    if (value instanceof FontUIResource)
    {
    UIManager.put(key, f);
    }
    }
    } /**
     * Create the frame
     */
    public JFileChooserTest()
    {
    super();
    setIconImage(SwingResourceManager.getImage(JFileChooserTest.class, "/s2t.gif"));
    setTitle("测试打开文件对话框");
    Font f = new Font("", Font.PLAIN, 14);
    setUIFont(f);
    setExtendedState(JFrame.MAXIMIZED_BOTH);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JButton button = new JButton();
    button.addMouseListener(new MouseAdapter()
    {
    public void mousePressed(MouseEvent e)
    {
    JFileChooser chooser = new JFileChooser();
    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(JFileChooserTest.this))
    {
    System.out.println(chooser.getSelectedFile().getAbsolutePath());
    }
    }
    });
    button.setText("New JButton");
    getContentPane().add(button, BorderLayout.CENTER);
    //
    }
    }
      

  3.   

    import com.swtdesigner.SwingResourceManager;这个类哪里有找呢?