This discussion is archived
1 Reply Latest reply: Apr 5, 2007 9:24 AM by 807596 RSS

Timely JFileChooser

807596 Newbie
Currently Being Moderated
When I pressed a JButton to display a JFileChooser, it takes longer sometimes than others.

There is enough of a delay that it makes me question whether I pressed the button or not.

I changed the cursor to a wait cursor, which I release after creating the JFileChoser, however that has issues.

I was trying to give some feedback that the button was pressed and to please wait.
public void actionPerformed(ActionEvent e)
{
     if (e.getSource() == browserButton())
     {
          setBusyCursor();
          JFileChooser chooser = new JFileChooser(....);   
          setDefaultCursor();
          .....
          // do whatever work with the selected directory/file....
     }
} 
Is there another workaround for this...

This works, but setting a busy cursor takes an EventQueue slot -- and perhaps, I'm not sure if, it also adds xx time to the JFileChooser appearing.

WIth that, the cursor seems to remain a busy cursor after the chooser appears -- until you move the mouse.
  • 1. Re: Timely JFileChooser
    807596 Newbie
    Currently Being Moderated
    I found some documentation on this solution ... but I'm not sure if it's a good work around.

    Advice... ??

    What I found was creating the JFileChoose in a SwingWorker and calling the get() method on the SwingWorker to return the JFileChooser.
    public void displayJFileChooser()
    {     
         SwingWorker createJFileChooser = new SwingWorker()
         {
              public Object construct()
              {
                   return new JFileChooser();
              }
         };
    
         createJFileChoser.start();
         JFileChooser chooser = createJFileChooser.get();
         chooser.showOpenDialog(this);
    }
    Any advice ??

    I have a UI that is responding very slow to calls to JFileChooser and JDialogs ...

    Thanks.