Discussion:
Finally a WaitCursor routine that works in NetBeans
George Mills
2003-01-21 14:51:40 UTC
Permalink
Check this nifty routine out.

The entire UI is prevented from the user taking any action, but the UI is
still running free.

public class WaitCursor
{
JFrame mMainFrame;

JComponent mGlassPane;

/** Constructor to set wait cursor with no status message */
public WaitCursor()
{
init();
}

/**
* Constructor to set wait cursor with status message to be displayed on
status bar
*
* @param title Specifies text to place in NetBeans titlebar
*/
public WaitCursor(String title)
{
TopManager.getDefault().setStatusText(title);
init();
}

/** common init routine for both constructors */
private void init()
{

// create component that eats everything
mGlassPane = new JComponent()
{
public void processKeyEvent(KeyEvent e)
{
e.consume();
}
};

mGlassPane.addMouseListener( new MouseAdapter() {} );

// now set it as the mainframes glasspane
mMainFrame = ((JFrame) WindowManager.getDefault().getMainWindow());
mMainFrame.setGlassPane(mGlassPane);

// set cursor on mainframe and glasspane (why both I don't know)

mMainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

mGlassPane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

// enable glasspane
mGlassPane.setVisible(true);
mGlassPane.requestFocus();

// tickle it
mGlassPane.getToolkit().sync();
}

/** restore Cursor to default and set no status */
public void restore()
{
mGlassPane.setVisible(false);

mMainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
TopManager.getDefault().setStatusText("");
}
}
Tim Boudreau
2003-01-22 09:47:00 UTC
Permalink
Interesting. Actually, buried in this would be one (ugly) way
to solve the problem of the help window and modal dialogs -
don't use real modal dialogs, but fake modality using a
technique like yours. Of course, it would need to be system
wide to work, and in MDI mode you'd need to do this for all
frames (except the help window)
but if DialogDisplayer could do it, it could
work...

-Tim
Post by George Mills
Check this nifty routine out.
The entire UI is prevented from the user taking any action, but the UI is
still running free.
public class WaitCursor
{
JFrame mMainFrame;
JComponent mGlassPane;
/** Constructor to set wait cursor with no status message */
public WaitCursor()
{
init();
}
/**
* Constructor to set wait cursor with status message to be displayed on
status bar
*
*/
public WaitCursor(String title)
{
TopManager.getDefault().setStatusText(title);
init();
}
/** common init routine for both constructors */
private void init()
{
// create component that eats everything
mGlassPane = new JComponent()
{
public void processKeyEvent(KeyEvent e)
{
e.consume();
}
};
mGlassPane.addMouseListener( new MouseAdapter() {} );
// now set it as the mainframes glasspane
mMainFrame = ((JFrame) WindowManager.getDefault().getMainWindow());
mMainFrame.setGlassPane(mGlassPane);
// set cursor on mainframe and glasspane (why both I don't know)
mMainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
mGlassPane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
// enable glasspane
mGlassPane.setVisible(true);
mGlassPane.requestFocus();
// tickle it
mGlassPane.getToolkit().sync();
}
/** restore Cursor to default and set no status */
public void restore()
{
mGlassPane.setVisible(false);
mMainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
TopManager.getDefault().setStatusText("");
}
}
Jesse Glick
2003-01-22 22:29:23 UTC
Permalink
Post by Tim Boudreau
Interesting. Actually, buried in this would be one (ugly) way
to solve the problem of the help window and modal dialogs -
Another would be to avoid any nontrivial modal dialogs (= those with
enough options to ever need help), which IMHO would be an improvement
anyway - a question to be brought up (once again) on nbui.

-Jesse
--
Jesse Glick <mailto:***@sun.com> x22801
NetBeans, Open APIs <http://www.netbeans.org/>
Loading...