Results 1 to 5 of 5
  1. #1
    CoffeeBeans is offline Member
    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    Default Navigation view Issue + com.sun.java.swing.plaf.windows.WindowsLookAndFeel

    Hi
    'm working on an Desktop application and facing problem with the look and feel while working with Windows 7 system.

    i'm using the "com.sun.java.swing.plaf.windows.WindowsLookAndFee l" with the JFileChooser and 'm unable to view the folder options when trying to open/save any file to the disk.

    Can you please help me out with this.

    'm sure its the code that lacks to inherit this feature from windows 7.

    (PS: this issue in only faced when the application is run on windows 7)

    Navigation view Issue + com.sun.java.swing.plaf.windows.WindowsLookAndFeel-windows-laf.png
    Last edited by CoffeeBeans; 10-23-2012 at 01:14 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,422
    Rep Power
    20

    Default Re: Navigation view Issue + com.sun.java.swing.plaf.windows.WindowsLookAndFeel

    Screenshots don't help much. To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.

    db

    edit Don't bother.

    Cross posted
    https://forums.oracle.com/forums/thr...55448&tstart=0
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    CoffeeBeans is offline Member
    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    Default Re: Navigation view Issue + com.sun.java.swing.plaf.windows.WindowsLookAndFeel

    A Sample FileChooser Program

    The FileChooserExample.java source code is as follows and contains two subclasses:

    ExampleFileView.java an interface to the Swing FileView class
    ExampleFileFilter.java an interface to the Swing FileFilter class
    /*This is the shortest compiling example I could provide, The example I'm working on it terribly huge, but its exactly similar to this one*/
    Java Code:
    import javax.swing.*;
    import javax.swing.filechooser.*;
    
    import java.awt.*;
    import java.io.File;
    import java.awt.event.*;
    import java.beans.*;
    
    
    /**
     *
     * A demo which makes extensive use of the file chooser.
     *
     * 1.7 08/26/98
     * @author Jeff Dinkins
     */
    public class FileChooserExample extends JPanel implements ActionListener {
        static JFrame frame;
    
        static String metal= "Metal";
        static String metalClassName = "javax.swing.plaf.metal.MetalLookAndFeel";
    
        static String motif = "Motif";
        static String motifClassName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
    
        static String windows = "Windows";
        static String windowsClassName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
    
    
        JButton button;
        JCheckBox useFileViewButton, accessoryButton, hiddenButton, showFullDescriptionButton;
        JRadioButton noFilterButton, addFiltersButton;
        JRadioButton openButton, saveButton, customButton;
        JRadioButton metalButton, motifButton, windowsButton;
        JRadioButton justFilesButton, justDirectoriesButton, bothFilesAndDirectoriesButton;
    
        JTextField customField;
    
        ExampleFileFilter jpgFilter, gifFilter, bothFilter;
        ExampleFileView fileView;
    
        JPanel buttonPanel;
    
        public final static Dimension hpad10 = new Dimension(10,1);
        public final static Dimension vpad10 = new Dimension(1,10);
    
        FilePreviewer previewer;
        JFileChooser chooser;
    
        public FileChooserExample() {
    	setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    
    	chooser = new JFileChooser();
    	previewer = new FilePreviewer(chooser);
    	chooser.setAccessory(previewer);
    
    	jpgFilter = new ExampleFileFilter("jpg", "JPEG Compressed Image Files");
    	gifFilter = new ExampleFileFilter("gif", "GIF Image Files");
    	bothFilter = new ExampleFileFilter(new String[] {"jpg", "gif"}, "JPEG and GIF Image Files");
    
    	fileView = new ExampleFileView();
    	fileView.putIcon("jpg", new ImageIcon("http://www.java-forums.org/images/jpgIcon.jpg"));
    	fileView.putIcon("gif", new ImageIcon("http://www.java-forums.org/images/gifIcon.gif"));
    
    	chooser.setAccessory(previewer);
    	chooser.setFileView(fileView);
    
    	// create a radio listener to listen to option changes
    	OptionListener optionListener = new OptionListener();
    
    	// Create options
    	openButton = new JRadioButton("Open");
    	openButton.setSelected(true);
    	openButton.addActionListener(optionListener);
    
    	saveButton = new JRadioButton("Save");
    	saveButton.addActionListener(optionListener);
    
    	customButton = new JRadioButton("Custom");
    	customButton.addActionListener(optionListener);
    
    	customField = new JTextField("Doit");
    	customField.setAlignmentY(JComponent.TOP_ALIGNMENT);
    	customField.setEnabled(false);
    	customField.addActionListener(optionListener);
    
    	ButtonGroup group1 = new ButtonGroup();
    	group1.add(openButton);
    	group1.add(saveButton);
    	group1.add(customButton);
    
    	// filter buttons
    	noFilterButton = new JRadioButton("No Filtering");
    	noFilterButton.setSelected(true);
    	noFilterButton.addActionListener(optionListener);
    
    	addFiltersButton = new JRadioButton("Add JPG and GIF Filters");
    	addFiltersButton.addActionListener(optionListener);
    
    	ButtonGroup group2 = new ButtonGroup();
    	group2.add(noFilterButton);
    	group2.add(addFiltersButton);
    
    	accessoryButton = new JCheckBox("Show Preview");
    	accessoryButton.addActionListener(optionListener);
    	accessoryButton.setSelected(true);
    
    	// more options
    	hiddenButton = new JCheckBox("Show Hidden Files");
    	hiddenButton.addActionListener(optionListener);
    
    	showFullDescriptionButton = new JCheckBox("Show Extensions");
    	showFullDescriptionButton.addActionListener(optionListener);
    	showFullDescriptionButton.setSelected(true);
    
    	useFileViewButton = new JCheckBox("Use FileView");
    	useFileViewButton.addActionListener(optionListener);
    	useFileViewButton.setSelected(true);
    
    	// File or Directory chooser options
    	ButtonGroup group3 = new ButtonGroup();
    	justFilesButton = new JRadioButton("Just Select Files");
    	justFilesButton.setSelected(true);
    	group3.add(justFilesButton);
    	justFilesButton.addActionListener(optionListener);
    
    	justDirectoriesButton = new JRadioButton("Just Select Directories");
    	group3.add(justDirectoriesButton);
    	justDirectoriesButton.addActionListener(optionListener);
    
    	bothFilesAndDirectoriesButton = new JRadioButton("Select Files or Directories");
    	group3.add(bothFilesAndDirectoriesButton);
    	bothFilesAndDirectoriesButton.addActionListener(optionListener);
    
    	// Create show button
    	button = new JButton("Show FileChooser");
    	button.addActionListener(this);
            button.setMnemonic('s');
    
    	// Create laf buttons.
    	metalButton = new JRadioButton(metal);
            metalButton.setMnemonic('o');
    	metalButton.setActionCommand(metalClassName);
    
    	motifButton = new JRadioButton(motif);
            motifButton.setMnemonic('m');
    	motifButton.setActionCommand(motifClassName);
    
    	windowsButton = new JRadioButton(windows);
            windowsButton.setMnemonic('w');
    	windowsButton.setActionCommand(windowsClassName);
    
    	ButtonGroup group4 = new ButtonGroup();
    	group4.add(metalButton);
    	group4.add(motifButton);
    	group4.add(windowsButton);
    
            // Register a listener for the laf buttons.
    	metalButton.addActionListener(optionListener);
    	motifButton.addActionListener(optionListener);
    	windowsButton.addActionListener(optionListener);
    
    	JPanel control1 = new JPanel();
    	control1.setLayout(new BoxLayout(control1, BoxLayout.X_AXIS));
    	control1.add(Box.createRigidArea(hpad10));
    	control1.add(openButton);
    	control1.add(Box.createRigidArea(hpad10));
    	control1.add(saveButton);
    	control1.add(Box.createRigidArea(hpad10));
    	control1.add(customButton);
    	control1.add(customField);
    	control1.add(Box.createRigidArea(hpad10));
    
    	JPanel control2 = new JPanel();
    	control2.setLayout(new BoxLayout(control2, BoxLayout.X_AXIS));
    	control2.add(Box.createRigidArea(hpad10));
    	control2.add(noFilterButton);
    	control2.add(Box.createRigidArea(hpad10));
    	control2.add(addFiltersButton);
    	control2.add(Box.createRigidArea(hpad10));
    	control2.add(accessoryButton);
    	control2.add(Box.createRigidArea(hpad10));
    
    	JPanel control3 = new JPanel();
    	control3.setLayout(new BoxLayout(control3, BoxLayout.X_AXIS));
    	control3.add(Box.createRigidArea(hpad10));
    	control3.add(hiddenButton);
    	control3.add(Box.createRigidArea(hpad10));
    	control3.add(showFullDescriptionButton);
    	control3.add(Box.createRigidArea(hpad10));
    	control3.add(useFileViewButton);
    	control3.add(Box.createRigidArea(hpad10));
    
    	JPanel control4 = new JPanel();
    	control4.setLayout(new BoxLayout(control4, BoxLayout.X_AXIS));
    	control4.add(Box.createRigidArea(hpad10));
    	control4.add(justFilesButton);
    	control4.add(Box.createRigidArea(hpad10));
    	control4.add(justDirectoriesButton);
    	control4.add(Box.createRigidArea(hpad10));
    	control4.add(bothFilesAndDirectoriesButton);
    	control4.add(Box.createRigidArea(hpad10));
    
    	JPanel panel = new JPanel();
    	panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
    	panel.add(Box.createRigidArea(hpad10));
    	panel.add(button);
    	panel.add(Box.createRigidArea(hpad10));
    	panel.add(metalButton);
    	panel.add(Box.createRigidArea(hpad10));
    	panel.add(motifButton);
    	panel.add(Box.createRigidArea(hpad10));
    	panel.add(windowsButton);
    	panel.add(Box.createRigidArea(hpad10));
    
    	add(Box.createRigidArea(vpad10));
    	add(control1);
    	add(Box.createRigidArea(vpad10));
    	add(control2);
    	add(Box.createRigidArea(vpad10));
    	add(control3);
    	add(Box.createRigidArea(vpad10));
    	add(control4);
    	add(Box.createRigidArea(vpad10));
    	add(Box.createRigidArea(vpad10));
    	add(panel);
    	add(Box.createRigidArea(vpad10));
        }
    
        public void actionPerformed(ActionEvent e) {
    	int retval = chooser.showDialog(frame, null);
    	if(retval == JFileChooser.APPROVE_OPTION) {
    	    File theFile = chooser.getSelectedFile();
    	    if(theFile != null) {
    		if(theFile.isDirectory()) {
    		    JOptionPane.showMessageDialog(
    			frame, "You chose this directory: " +
    			chooser.getSelectedFile().getAbsolutePath()
    		    );
    		} else {
    		    JOptionPane.showMessageDialog(
    			frame, "You chose this file: " +
    			chooser.getSelectedFile().getAbsolutePath()
    		    );
    		}
    		return;
    	    }
    	}
    	JOptionPane.showMessageDialog(frame, "No file was chosen.");
        }
    
        /** An ActionListener that listens to the radio buttons. */
        class OptionListener implements ActionListener {
    	public void actionPerformed(ActionEvent e) {
    	    JComponent c = (JComponent) e.getSource();
    	    if(c == openButton) {
    		chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    		customField.setEnabled(false);
    		repaint();
    	    } else if (c == saveButton) {
    		chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    		customField.setEnabled(false);
    		repaint();
    	    } else if (c == customButton || c == customField) {
    		customField.setEnabled(true);
    		chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
    		chooser.setApproveButtonText(customField.getText());
    		repaint();
    	    } else if(c == noFilterButton) {
    		chooser.resetChoosableFileFilters();
    	    } else if(c == addFiltersButton) {
    		chooser.addChoosableFileFilter(bothFilter);
    		chooser.addChoosableFileFilter(jpgFilter);
    		chooser.addChoosableFileFilter(gifFilter);
    	    } else if(c == hiddenButton) {
    		chooser.setFileHidingEnabled(!hiddenButton.isSelected());
    	    } else if(c == accessoryButton) {
    		if(accessoryButton.isSelected()) {
    		    chooser.setAccessory(previewer);
    		} else {
    		    chooser.setAccessory(null);
    		}
    	    } else if(c == useFileViewButton) {
    		if(useFileViewButton.isSelected()) {
    		    chooser.setFileView(fileView);
    		} else {
    		    chooser.setFileView(null);
    		}
    	    } else if(c == showFullDescriptionButton) {
    		jpgFilter.setExtensionListInDescription(showFullDescriptionButton.isSelected());
    		gifFilter.setExtensionListInDescription(showFullDescriptionButton.isSelected());
    		bothFilter.setExtensionListInDescription(showFullDescriptionButton.isSelected());
    		if(addFiltersButton.isSelected()) {
    		    chooser.resetChoosableFileFilters();
    		    chooser.addChoosableFileFilter(bothFilter);
    		    chooser.addChoosableFileFilter(jpgFilter);
    		    chooser.setFileFilter(gifFilter);
    		}
    	    } else if(c == justFilesButton) {
    		chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    	    } else if(c == justDirectoriesButton) {
    		chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    	    } else if(c == bothFilesAndDirectoriesButton) {
    		chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    	    } else {
    		String lnfName = e.getActionCommand();
    
    		try {
    		    UIManager.setLookAndFeel(lnfName);
    		    SwingUtilities.updateComponentTreeUI(frame);
    		    if(chooser != null) {
    			SwingUtilities.updateComponentTreeUI(chooser);
    		    }
    		    frame.pack();
    		} catch (UnsupportedLookAndFeelException exc) {
    		    System.out.println("Unsupported Look and Feel Error:" + exc);
    		    JRadioButton button = (JRadioButton)e.getSource();
    		    button.setEnabled(false);
    		    updateState();
    		} catch (IllegalAccessException exc) {
    		    System.out.println("IllegalAccessException Error:" + exc);
    		} catch (ClassNotFoundException exc) {
    		    System.out.println("ClassNotFoundException Error:" + exc);
    		} catch (InstantiationException exc) {
    		    System.out.println("InstantiateException Error:" + exc);
    		}
    	    }
    
    	}
        }
    
        public void updateState() {
    	String lnfName = UIManager.getLookAndFeel().getClass().getName();
    	if (lnfName.indexOf(metal) >= 0) {
    	    metalButton.setSelected(true);
    	} else if (lnfName.indexOf(windows) >= 0) {
    	    windowsButton.setSelected(true);
    	} else if (lnfName.indexOf(motif) >= 0) {
    	    motifButton.setSelected(true);
    	} else {
    	    System.err.println("FileChooserExample if using an unknown  Look and Feel: " + lnfName);
    	}
        }
    
        class FilePreviewer extends JComponent implements PropertyChangeListener {
    	ImageIcon thumbnail = null;
    	File f = null;
    
    	public FilePreviewer(JFileChooser fc) {
    	    setPreferredSize(new Dimension(100, 50));
    	    fc.addPropertyChangeListener(this);
    	}
    
    	public void loadImage() {
    	    if(f != null) {
    		ImageIcon tmpIcon = new ImageIcon(f.getPath());
    		if(tmpIcon.getIconWidth() > 90) {
    		    thumbnail = new ImageIcon(
    			tmpIcon.getImage().getScaledInstance(90, -1, Image.SCALE_DEFAULT));
    		} else {
    		    thumbnail = tmpIcon;
    		}
    	    }
    	}
    
    	public void propertyChange(PropertyChangeEvent e) {
    	    String prop = e.getPropertyName();
    	    if(prop == JFileChooser.SELECTED_FILE_CHANGED_PROPERTY) {
    		f = (File) e.getNewValue();
    		if(isShowing()) {
    		    loadImage();
    		    repaint();
    		}
    	    }
    	}
    
    	public void paint(Graphics g) {
    	    if(thumbnail == null) {
    		loadImage();
    	    }
    	    if(thumbnail != null) {
    		int x = getWidth()/2 - thumbnail.getIconWidth()/2;
    		int y = getHeight()/2 - thumbnail.getIconHeight()/2;
    		if(y < 0) {
    		    y = 0;
    		}
    
    		if(x < 5) {
    		    x = 5;
    		}
    		thumbnail.paintIcon(this, g, x, y);
    	    }
    	}
        }
    
        public static void main(String s[]) {
    	/*
    	   NOTE: By default, the look and feel will be set to the
    	   Cross Platform Look and Feel (which is currently Metal).
    	   The user may someday be able to override the default
    	   via a system property. If you as the developer want to
    	   be sure that a particular {\em Look and Feel} is set, you can do so
    	   by calling UIManager.setLookAndFeel(). For example, the
    	   first code snippet below forcibly sets the UI to be the
    	   System Look and Feel. The second code snippet forcibly
    	   sets the look and feel to the Cross Platform {\em Look and Feel}.
    
    	   Snippet 1:
    	   try {
    	      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    	   } catch (Exception exc) {
    	      System.err.println("Error loading  Look and Feel: " + exc);
    	   }
    
    	   Snippet 2:
    	   try {
    	      UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    	   } catch (Exception exc) {
    	      System.err.println("Error loading  Look and Feel: " + exc);
    	   }
    	*/
    
    	try {
    	    // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    	    UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    	} catch (Exception exc) {
    	    System.err.println("Error loading  Look and Feel: " + exc);
    	}
    
    	FileChooserExample panel = new FileChooserExample();
    
    	frame = new JFrame("FileChooserExample");
    	frame.addWindowListener(new WindowAdapter() {
    	    public void windowClosing(WindowEvent e) {System.exit(0);}
    	});
    	frame.getContentPane().add("Center", panel);
    	frame.pack();
    	frame.setVisible(true);
    
    	panel.updateState();
        }
    }
    The ExampleFileFilter.java class source code is as follows

    Java Code:
    import java.io.File;
    import java.util.Hashtable;
    import java.util.Enumeration;
    import javax.swing.*;
    import javax.swing.filechooser.*;
    
    /**
     * A convenience implementation of FileFilter that filters out
     * all files except for those type extensions that it knows about.
     *
     * Extensions are of the type ".foo", which is typically found on
     * Windows and Unix boxes, but not on Macinthosh. Case is ignored.
     *
     * Example - create a new filter that filerts out all files
     * but gif and jpg image files:
     *
     *     JFileChooser chooser = new JFileChooser();
     *     ExampleFileFilter filter = new ExampleFileFilter(
     *                   new String{"gif", "jpg"}, "JPEG & GIF Images")
     *     chooser.addChoosableFileFilter(filter);
     *     chooser.showOpenDialog(this);
     *
     * @version 1.8 08/26/98
     * @author Jeff Dinkins
     */
    public class ExampleFileFilter extends FileFilter {
    
        private static String TYPE_UNKNOWN = "Type Unknown";
        private static String HIDDEN_FILE = "Hidden File";
    
        private Hashtable filters = null;
        private String description = null;
        private String fullDescription = null;
        private boolean useExtensionsInDescription = true;
    
        /**
         * Creates a file filter. If no filters are added, then all
         * files are accepted.
         *
         * @see #addExtension
         */
        public ExampleFileFilter() {
    	this.filters = new Hashtable();
        }
    
        /**
         * Creates a file filter that accepts files with the given extension.
         * Example: new ExampleFileFilter("jpg");
         *
         * @see #addExtension
         */
        public ExampleFileFilter(String extension) {
    	this(extension,null);
        }
    
        /**
         * Creates a file filter that accepts the given file type.
         * Example: new ExampleFileFilter("jpg", "JPEG Image Images");
         *
         * Note that the "." before the extension is not needed. If
         * provided, it will be ignored.
         *
         * @see #addExtension
         */
        public ExampleFileFilter(String extension, String description) {
    	this();
    	if(extension!=null) addExtension(extension);
     	if(description!=null) setDescription(description);
        }
    
        /**
         * Creates a file filter from the given string array.
         * Example: new ExampleFileFilter(String {"gif", "jpg"});
         *
         * Note that the "." before the extension is not needed adn
         * will be ignored.
         *
         * @see #addExtension
         */
        public ExampleFileFilter(String[] filters) {
    	this(filters, null);
        }
    
        /**
         * Creates a file filter from the given string array and description.
         * Example: new ExampleFileFilter(String {"gif", "jpg"}, "Gif and JPG Images");
         *
         * Note that the "." before the extension is not needed and will be ignored.
         *
         * @see #addExtension
         */
        public ExampleFileFilter(String[] filters, String description) {
    	this();
    	for (int i = 0; i < filters.length; i++) {
    	    // add filters one by one
    	    addExtension(filters[i]);
    	}
     	if(description!=null) setDescription(description);
        }
    
        /**
         * Return true if this file should be shown in the directory pane,
         * false if it shouldn't.
         *
         * Files that begin with "." are ignored.
         *
         * @see #getExtension
         * @see FileFilter#accepts
         */
        public boolean accept(File f) {
    	if(f != null) {
    	    if(f.isDirectory()) {
    		return true;
    	    }
    	    String extension = getExtension(f);
    	    if(extension != null && filters.get(getExtension(f)) != null) {
    		return true;
    	    };
    	}
    	return false;
        }
    
        /**
         * Return the extension portion of the file's name .
         *
         * @see #getExtension
         * @see FileFilter#accept
         */
         public String getExtension(File f) {
    	if(f != null) {
    	    String filename = f.getName();
    	    int i = filename.lastIndexOf('.');
    	    if(i>0 && i<filename.length()-1) {
    		return filename.substring(i+1).toLowerCase();
    	    };
    	}
    	return null;
        }
    
        /**
         * Adds a filetype "dot" extension to filter against.
         *
         * For example: the following code will create a filter that filters
         * out all files except those that end in ".jpg" and ".tif":
         *
         *   ExampleFileFilter filter = new ExampleFileFilter();
         *   filter.addExtension("jpg");
         *   filter.addExtension("tif");
         *
         * Note that the "." before the extension is not needed and will be ignored.
         */
        public void addExtension(String extension) {
    	if(filters == null) {
    	    filters = new Hashtable(5);
    	}
    	filters.put(extension.toLowerCase(), this);
    	fullDescription = null;
        }
    
    
        /**
         * Returns the human readable description of this filter. For
         * example: "JPEG and GIF Image Files (*.jpg, *.gif)"
         *
         * @see setDescription
         * @see setExtensionListInDescription
         * @see isExtensionListInDescription
         * @see FileFilter#getDescription
         */
        public String getDescription() {
    	if(fullDescription == null) {
    	    if(description == null || isExtensionListInDescription()) {
     		fullDescription = description==null ? "(" : description + " (";
    		// build the description from the extension list
    		Enumeration extensions = filters.keys();
    		if(extensions != null) {
    		    fullDescription += "." + (String) extensions.nextElement();
    		    while (extensions.hasMoreElements()) {
    			fullDescription += ", " + (String) extensions.nextElement();
    		    }
    		}
    		fullDescription += ")";
    	    } else {
    		fullDescription = description;
    	    }
    	}
    	return fullDescription;
        }
    
        /**
         * Sets the human readable description of this filter. For
         * example: filter.setDescription("Gif and JPG Images");
         *
         * @see setDescription
         * @see setExtensionListInDescription
         * @see isExtensionListInDescription
         */
        public void setDescription(String description) {
    	this.description = description;
    	fullDescription = null;
        }
    
        /**
         * Determines whether the extension list (.jpg, .gif, etc) should
         * show up in the human readable description.
         *
         * Only relevent if a description was provided in the constructor
         * or using setDescription();
         *
         * @see getDescription
         * @see setDescription
         * @see isExtensionListInDescription
         */
        public void setExtensionListInDescription(boolean b) {
    	useExtensionsInDescription = b;
    	fullDescription = null;
        }
    
        /**
         * Returns whether the extension list (.jpg, .gif, etc) should
         * show up in the human readable description.
         *
         * Only relevent if a description was provided in the constructor
         * or using setDescription();
         *
         * @see getDescription
         * @see setDescription
         * @see setExtensionListInDescription
         */
        public boolean isExtensionListInDescription() {
    	return useExtensionsInDescription;
        }
    }
    The ExampleFileView.java class source code is as follows

    Java Code:
    import javax.swing.*;
    import javax.swing.filechooser.*;
    
    import java.io.File;
    import java.util.Hashtable;
    
    /**
     * A convenience implementation of the FileView interface that
     * manages name, icon, traversable, and file type information.
     *
     * This this implemention will work well with file systems that use
     * "dot" extensions to indicate file type. For example: "picture.gif"
     * as a gif image.
     *
     * If the java.io.File ever contains some of this information, such as
     * file type, icon, and hidden file inforation, this implementation may
     * become obsolete. At minimum, it should be rewritten at that time to
     * use any new type information provided by java.io.File
     *
     * Example:
     *    JFileChooser chooser = new JFileChooser();
     *    fileView = new ExampleFileView();
     *    fileView.putIcon("jpg", new ImageIcon("http://www.java-forums.org/images/jpgIcon.jpg"));
     *    fileView.putIcon("gif", new ImageIcon("http://www.java-forums.org/images/gifIcon.gif"));
     *    chooser.setFileView(fileView);
     *
     * @version 1.7 08/26/98
     * @author Jeff Dinkins
     */
    public class ExampleFileView extends FileView {
        private Hashtable icons = new Hashtable(5);
        private Hashtable fileDescriptions = new Hashtable(5);
        private Hashtable typeDescriptions = new Hashtable(5);
    
        /**
         * The name of the file.  Do nothing special here. Let
         * the system file view handle this.
         * @see #setName
         * @see FileView#getName
         */
        public String getName(File f) {
    	return null;
        }
    
        /**
         * Adds a human readable description of the file.
         */
        public void putDescription(File f, String fileDescription) {
    	fileDescriptions.put(fileDescription, f);
        }
    
        /**
         * A human readable description of the file.
         *
         * @see FileView#getDescription
         */
        public String getDescription(File f) {
    	return (String) fileDescriptions.get(f);
        };
    
        /**
         * Adds a human readable type description for files. Based on "dot"
         * extension strings, e.g: ".gif". Case is ignored.
         */
        public void putTypeDescription(String extension, String typeDescription) {
    	typeDescriptions.put(typeDescription, extension);
        }
    
        /**
         * Adds a human readable type description for files of the type of
         * the passed in file. Based on "dot" extension strings, e.g: ".gif".
         * Case is ignored.
         */
        public void putTypeDescription(File f, String typeDescription) {
    	putTypeDescription(getExtension(f), typeDescription);
        }
    
        /**
         * A human readable description of the type of the file.
         *
         * @see FileView#getTypeDescription
         */
        public String getTypeDescription(File f) {
    	return (String) typeDescriptions.get(getExtension(f));
        }
    
        /**
         * Conveinience method that returnsa the "dot" extension for the
         * given file.
         */
        public String getExtension(File f) {
    	String name = f.getName();
    	if(name != null) {
    	    int extensionIndex = name.lastIndexOf('.');
    	    if(extensionIndex < 0) {
    		return null;
    	    }
    	    return name.substring(extensionIndex+1).toLowerCase();
    	}
    	return null;
        }
    
        /**
         * Adds an icon based on the file type "dot" extension
         * string, e.g: ".gif". Case is ignored.
         */
        public void putIcon(String extension, Icon icon) {
    	icons.put(extension, icon);
        }
    
        /**
         * Icon that reperesents this file. Default implementation returns
         * null. You might want to override this to return something more
         * interesting.
         *
         * @see FileView#getIcon
         */
        public Icon getIcon(File f) {
    	Icon icon = null;
    	String extension = getExtension(f);
    	if(extension != null) {
    	    icon = (Icon) icons.get(extension);
    	}
    	return icon;
        }
    
        /**
         * Whether the file is hidden or not. This implementation returns
         * true if the filename starts with a "."
         *
         * @see FileView#isHidden
         */
        public Boolean isHidden(File f) {
    	String name = f.getName();
    	if(name != null && !name.equals("") && name.charAt(0) == '.') {
    	    return Boolean.TRUE;
    	} else {
    	    return Boolean.FALSE;
    	}
        };
    
        /**
         * Whether the directory is traversable or not. Generic implementation
         * returns true for all directories.
         *
         * You might want to subtype ExampleFileView to do somethimg more interesting,
         * such as recognize compound documents directories; in such a case you might
         * return a special icon for the diretory that makes it look like a regular
         * document, and return false for isTraversable to not allow users to
         * descend into the directory.
         *
         * @see FileView#isTraversable
         */
        public Boolean isTraversable(File f) {
    	if(f.isDirectory()) {
    	    return Boolean.TRUE;
    	} else {
    	    return Boolean.FALSE;
    	}
        };
    
    }
    Last edited by CoffeeBeans; 10-25-2012 at 03:21 PM.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,422
    Rep Power
    20

    Default Re: Navigation view Issue + com.sun.java.swing.plaf.windows.WindowsLookAndFeel

    Kindly go through the SSCCE link and create a SSCCE. No volunteer enjoys going through reams of largely irrelevant code littered with inane doc comments.

    Also go through Guide For New Members and BB Code List - Java Programming Forum and edit your post accordingly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    CoffeeBeans is offline Member
    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    Default Re: Navigation view Issue + com.sun.java.swing.plaf.windows.WindowsLookAndFeel

    Thanx for the links....I'll remember all this while posting my next threads :)
    Last edited by CoffeeBeans; 10-25-2012 at 04:00 PM.

Similar Threads

  1. How to Integrate my Java Swing App with my Windows OS
    By peterorparker in forum AWT / Swing
    Replies: 2
    Last Post: 08-06-2011, 12:07 AM
  2. How To show Frames in Windows View in runtime?
    By The Ghost 88 in forum AWT / Swing
    Replies: 2
    Last Post: 05-26-2009, 10:38 AM
  3. Java Swing GUI Windows XP Flickering Probelm
    By hemanthjava in forum AWT / Swing
    Replies: 1
    Last Post: 12-12-2008, 03:07 PM
  4. [SOLVED] Navigation between swing forms
    By stevedb in forum AWT / Swing
    Replies: 7
    Last Post: 04-01-2008, 02:23 PM
  5. Create view of files in java-Swing
    By Albert in forum AWT / Swing
    Replies: 1
    Last Post: 07-06-2007, 07:06 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •