if (e.getPropertyName().equals( JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) { if (filechooser.getSelectedFile() == null) setFileName(null); else setFileName(filechooser.getSelectedFile().toString()); int index = -1; File file = filechooser.getSelectedFile(); for (index = 0; index < model.getSize(); index++) if (((File) model.getElementAt(index)).equals(file)) break; if (index == -1) return; filelist.setSelectedIndex(index); filelist.ensureIndexIsVisible(index); filelist.revalidate(); filelist.repaint(); } else if (e.getPropertyName().equals( JFileChooser.DIRECTORY_CHANGED_PROPERTY)) { filelist.clearSelection(); filelist.revalidate(); filelist.repaint(); setDirectorySelected(false); setDirectory(filechooser.getCurrentDirectory()); boxEntries(); } else if (e.getPropertyName().equals( JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) || e.getPropertyName().equals( JFileChooser.FILE_FILTER_CHANGED_PROPERTY)) filterEntries(); else if (e.getPropertyName().equals( JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY) || e.getPropertyName().equals( JFileChooser.DIALOG_TITLE_CHANGED_PROPERTY)) { Window owner = SwingUtilities.windowForComponent(filechooser); if (owner instanceof JDialog) ((JDialog) owner).setTitle(getDialogTitle(filechooser)); accept.setText(getApproveButtonText(filechooser)); accept.setToolTipText(getApproveButtonToolTipText(filechooser)); accept.setMnemonic(getApproveButtonMnemonic(filechooser)); } else if (e.getPropertyName().equals( JFileChooser.APPROVE_BUTTON_TEXT_CHANGED_PROPERTY)) accept.setText(getApproveButtonText(filechooser)); else if (e.getPropertyName().equals( JFileChooser.APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY)) accept.setToolTipText(getApproveButtonToolTipText(filechooser)); else if (e.getPropertyName().equals( JFileChooser.APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY)) accept.setMnemonic(getApproveButtonMnemonic(filechooser)); else if (e.getPropertyName().equals( JFileChooser.CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY)) { if (filechooser.getControlButtonsAreShown()) { GridBagConstraints c = new GridBagConstraints(); c.gridy = 1; bottomPanel.add(filters, c);  c.fill = GridBagConstraints.BOTH; c.gridy = 2; c.anchor = GridBagConstraints.EAST; bottomPanel.add(closePanel, c); bottomPanel.revalidate(); bottomPanel.repaint(); bottomPanel.doLayout(); } else bottomPanel.remove(closePanel); } else if (e.getPropertyName().equals( JFileChooser.ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY)) { if (filechooser.isAcceptAllFileFilterUsed()) filechooser.addChoosableFileFilter(getAcceptAllFileFilter(filechooser)); else filechooser.removeChoosableFileFilter(getAcceptAllFileFilter(filechooser)); } else if (e.getPropertyName().equals( JFileChooser.ACCESSORY_CHANGED_PROPERTY)) { JComponent old = (JComponent) e.getOldValue(); if (old != null) getAccessoryPanel().remove(old); JComponent newval = (JComponent) e.getNewValue(); if (newval != null) getAccessoryPanel().add(newval); } if (e.getPropertyName().equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY) || e.getPropertyName().equals( JFileChooser.FILE_FILTER_CHANGED_PROPERTY) || e.getPropertyName().equals( JFileChooser.FILE_HIDING_CHANGED_PROPERTY)) rescanCurrentDirectory(filechooser);  filechooser.revalidate(); filechooser.repaint();
  public PropertyChangeListener createPropertyChangeListener(JFileChooser fc)  {    return new PropertyChangeListener()    {      public void propertyChange(PropertyChangeEvent e)      {        // FIXME: Multiple file selection waiting on JList multiple selection        // bug.        if (e.getPropertyName().equals(                                       JFileChooser.SELECTED_FILE_CHANGED_PROPERTY))          {            if (filechooser.getSelectedFile() == null)              setFileName(null);            else              setFileName(filechooser.getSelectedFile().toString());            int index = -1;            File file = filechooser.getSelectedFile();            for (index = 0; index < model.getSize(); index++)              if (((File) model.getElementAt(index)).equals(file))                break;            if (index == -1)              return;            filelist.setSelectedIndex(index);            filelist.ensureIndexIsVisible(index);            filelist.revalidate();            filelist.repaint();          }        else if (e.getPropertyName().equals(                                            JFileChooser.DIRECTORY_CHANGED_PROPERTY))          {            filelist.clearSelection();            filelist.revalidate();            filelist.repaint();            setDirectorySelected(false);            setDirectory(filechooser.getCurrentDirectory());            boxEntries();          }        else if (e.getPropertyName().equals(                                            JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY)                 || e.getPropertyName().equals(                                               JFileChooser.FILE_FILTER_CHANGED_PROPERTY))          filterEntries();        else if (e.getPropertyName().equals(                                            JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY)                 || e.getPropertyName().equals(                                               JFileChooser.DIALOG_TITLE_CHANGED_PROPERTY))          {            Window owner = SwingUtilities.windowForComponent(filechooser);            if (owner instanceof JDialog)              ((JDialog) owner).setTitle(getDialogTitle(filechooser));            accept.setText(getApproveButtonText(filechooser));            accept.setToolTipText(getApproveButtonToolTipText(filechooser));            accept.setMnemonic(getApproveButtonMnemonic(filechooser));          }        else if (e.getPropertyName().equals(                                            JFileChooser.APPROVE_BUTTON_TEXT_CHANGED_PROPERTY))          accept.setText(getApproveButtonText(filechooser));        else if (e.getPropertyName().equals(                                            JFileChooser.APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY))          accept.setToolTipText(getApproveButtonToolTipText(filechooser));        else if (e.getPropertyName().equals(                                            JFileChooser.APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY))          accept.setMnemonic(getApproveButtonMnemonic(filechooser));        else if (e.getPropertyName().equals(                                            JFileChooser.CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY))          {            if (filechooser.getControlButtonsAreShown())              {                GridBagConstraints c = new GridBagConstraints();                c.gridy = 1;                bottomPanel.add(filters, c);                c.fill = GridBagConstraints.BOTH;                c.gridy = 2;                c.anchor = GridBagConstraints.EAST;                bottomPanel.add(closePanel, c);                bottomPanel.revalidate();                bottomPanel.repaint();                bottomPanel.doLayout();              }            else              bottomPanel.remove(closePanel);          }        else if (e.getPropertyName().equals(                                            JFileChooser.ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY))          {            if (filechooser.isAcceptAllFileFilterUsed())              filechooser.addChoosableFileFilter(getAcceptAllFileFilter(filechooser));            else              filechooser.removeChoosableFileFilter(getAcceptAllFileFilter(filechooser));          }        else if (e.getPropertyName().equals(                                            JFileChooser.ACCESSORY_CHANGED_PROPERTY))          {            JComponent old = (JComponent) e.getOldValue();            if (old != null)              getAccessoryPanel().remove(old);            JComponent newval = (JComponent) e.getNewValue();            if (newval != null)              getAccessoryPanel().add(newval);          }        if (e.getPropertyName().equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)            || e.getPropertyName().equals(                                          JFileChooser.FILE_FILTER_CHANGED_PROPERTY)            || e.getPropertyName().equals(                                          JFileChooser.FILE_HIDING_CHANGED_PROPERTY))          rescanCurrentDirectory(filechooser);        filechooser.revalidate();        filechooser.repaint();      }    };  }