Event Handling - Timely JFileChooser

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.

publicvoid 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.

[1360 byte] By [-Deba] at [2007-11-26 23:32:25]
# 1

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.

-Deba at 2007-7-10 14:45:00 > top of Java-index,Security,Event Handling...