Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5087935

Reg: Changing LAF at Runtime displays class name in Filter of JFileChooser - GTK

XMLWordPrintable

        When LAF is changed to GTK at runtime, the Filter displays class name instead of description of the filter. This works fine in 1.4.2

        Compile and run JFileChooserTest.java
        Change LAF to GTK by choosing GTK from menu
        Click on button to display JFileChooser
        The contents of filter will be its class name

        Refer to attached screen shot
        I am adding the attached test case JFileChooserTest.java to the description
        so it will be visible to the community at large:


        import javax.swing.*;
        import javax.swing.filechooser.*;
        import java.awt.*;
        import java.awt.event.*;

        public class JFileChooserTest {

            private static final String metal =
                "javax.swing.plaf.metal.MetalLookAndFeel";
            private static final String motif =
                "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
            private static final String gtk =
                "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";

            private JFileChooser fileChooser = null;
            private JFrame frame = null;

            public JFileChooserTest() {

                frame = new JFrame("Custom Filter JFileChooser Test");
                frame.getContentPane().setLayout(new FlowLayout());
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                initMenu();

                fileChooser = new JFileChooser();

                JButton button = new JButton("Show Open JFileChooser");
                button.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        fileChooser.showOpenDialog((Component)ae.getSource());
                    }
                });

                frame.getContentPane().add(button);
                frame.setSize(300, 300);
                frame.setVisible(true);
            }

            private void initMenu() {

                JMenuBar menuBar = new JMenuBar();

                JMenu menu = new JMenu("Look And Feel");
                
                MenuListener ml = new MenuListener();

                JMenuItem menuMetalLAF = new JMenuItem("Metal");
                menuMetalLAF.setActionCommand(metal);
                menuMetalLAF.addActionListener(ml);
                menu.add(menuMetalLAF);

                JMenuItem menuMotifLAF = new JMenuItem("Motif");
                menuMotifLAF.setActionCommand(motif);
                menuMotifLAF.addActionListener(ml);
                menu.add(menuMotifLAF);

                JMenuItem menuGTKSunLAF = new JMenuItem("GTK");
                menuGTKSunLAF.setActionCommand(gtk);
                menuGTKSunLAF.addActionListener(ml);
                menu.add(menuGTKSunLAF);

                menuBar.add(menu);
                frame.setJMenuBar(menuBar);
            }

            public static void main(String args[]) throws Exception {
                new JFileChooserTest();
            }

            private void setLookAndFeel(String string) {
                try {
                    System.out.println(string);
                    UIManager.setLookAndFeel(string);
                    SwingUtilities.updateComponentTreeUI(frame);
                    SwingUtilities.updateComponentTreeUI(fileChooser);
                }
                catch(Exception e) {
                    System.err.println("Exception : " + e);
                }
            }

            private class MenuListener implements ActionListener {
                public void actionPerformed(ActionEvent ae) {
                    JMenuItem menuItem = (JMenuItem) ae.getSource();
                    setLookAndFeel(menuItem.getActionCommand());
                }
            }
        }

              Unassigned Unassigned
              rmenonsunw Rakesh Menon (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: