George Mills
2003-01-21 14:51:40 UTC
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("");
}
}
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("");
}
}