Java Code Examples for javax.swing.JFileChooser#updateUI()

The following examples show how to use javax.swing.JFileChooser#updateUI() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RemoteSessionChooserFactory.java    From chipster with MIT License 6 votes vote down vote up
public static ServerFileSystemView updateRemoteSessions(SessionManager sessionManager,
		JFileChooser sessionFileChooser, boolean excludeExampleSessions) throws FileBrokerException, MalformedURLException, AuthCancelledException {
	List<DbSession> sessions = sessionManager.listRemoteSessions();
	
	// hide example sessions
	if (excludeExampleSessions) {
		List<DbSession> sessionsToHide = new LinkedList<DbSession>();
		for (DbSession session: sessions) {
			if (session.getName().startsWith(DerbyMetadataServer.DEFAULT_EXAMPLE_SESSION_FOLDER)) {
				sessionsToHide.add(session);
			}
		}
		sessions.removeAll(sessionsToHide);
	}
		
	ServerFileSystemView view = ServerFileSystemView.parseFromPaths(ServerFile.SERVER_SESSION_ROOT_FOLDER, sessions);		
	sessionFileChooser.setFileSystemView(view);
	// without this the GUI doesn't update when a session is removed
	sessionFileChooser.setCurrentDirectory(null);
	sessionFileChooser.setCurrentDirectory(view.getRoot());		
	sessionFileChooser.putClientProperty("sessions", sessions);
	// without this removed sessions are shown after folder change
	sessionFileChooser.updateUI();
	return view;
}
 
Example 2
Source File: Upgrader.java    From tracker with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Uses a JFileChooser to select a download directory.
 * 
 * @param parent a component to own the file chooser
 * @param likely the default likely directory
 * @return the chosen directory file
 */
private File chooseDownloadDirectory(Component parent, File likely) {

	JFileChooser chooser = new JFileChooser() {
    public void approveSelection() {
        if (getSelectedFile().isFile()) {
            return;
        } else
            super.approveSelection();
    }
};
  chooser.setDialogTitle(TrackerRes.getString("TTrackBar.Chooser.DownloadDirectory")); //$NON-NLS-1$		
  chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  javax.swing.filechooser.FileFilter folderFilter = new javax.swing.filechooser.FileFilter() {
    // accept directories only
    public boolean accept(File f) {
    	if (f==null) return false;
    	if (f.getName().endsWith(".app")) return false; //$NON-NLS-1$
      return f.isDirectory();
    }
    public String getDescription() {
      return ToolsRes.getString("LibraryTreePanel.FolderFileFilter.Description"); //$NON-NLS-1$
    } 	     	
  };
  chooser.setAcceptAllFileFilterUsed(false);
  chooser.addChoosableFileFilter(folderFilter);
  chooser.setCurrentDirectory(new File(likely.getParent()));
  chooser.setSelectedFile(likely);
  if (OSPRuntime.isMac()) {
  	chooser.updateUI();
  }
	FontSizer.setFonts(chooser, FontSizer.getLevel());
 int result = chooser.showDialog(parent, TrackerRes.getString("Dialog.Button.OK")); //$NON-NLS-1$
  if (result==JFileChooser.APPROVE_OPTION) {
    return chooser.getSelectedFile();
  }
	return null;
}