Article View: borland.public.jbuilder.java.swing
Article #9975Hourglass cursor, glasspane and keyboard hotkeys
From: Markus Schwarz
Date: Fri, 03 Dec 1999 00:00
Date: Fri, 03 Dec 1999 00:00
100 lines
3616 bytes
3616 bytes
Hi there,
I have to display a hourglass cursor, as we know it from any Windows
Programm.
If I want to do this the Visual C++ and MFC-way, I simply type
CWaitCurser wait;
in the function where my lengthly processing occur.
But I want to do it in Java. The java Tutorial told me from the
glassPane property of a JFrame, so I set this property of my JFrame to
this
JComponent, which should disable all user input.
public class EmptyGlassPane extends JComponent implements KeyListener,
MouseListener{
public EmptyGlassPane() {
super.addKeyListener( this );
super.addMouseListener( this );
}
public void setVisible(boolean enabled) {
Cursor cursor = Cursor.getPredefinedCursor( enabled ?
Cursor.WAIT_CURSOR :
Cursor.DEFAULT_CURSOR );
super.setCursor(cursor);
super.enableInputMethods(!enabled);
super.setVisible(enabled);
}
public void keyTyped(KeyEvent e) { e.consume(); }
public void keyPressed(KeyEvent e) { e.consume(); }
public void keyReleased(KeyEvent e) { e.consume(); }
public void mouseClicked(MouseEvent e) {e.consume(); }
public void mousePressed(MouseEvent e) {e.consume(); }
public void mouseReleased(MouseEvent e){e.consume(); }
public void mouseEntered(MouseEvent e) {e.consume(); }
public void mouseExited(MouseEvent e) { e.consume(); }
}
After the glasspane property of my JFrame was set to this component and
my Application runs, I want to activate It (whenever a lengthly
processing should be done) this way:
mainFrame.getGlassPane().setVisible(true);
Know I came into trouble. I almost avery cases I want to activate and
deactivate the glassPane in an actionPerformed(..)-method of an
ActionListener.
But this doesn't work. Because I am in the Event-Thread, where
GUI-updating is not possible, so I helped myself via this contruct:
public void actionPerformed( ActionEvent ae ) {
if ( menuNode != null ) {
SwingUtilities.invokeLater(new Runnable(){
public void run(){
new WorkerThread().start();
}
});
mainFrame.getGlassPane().setVisible( true );
}
}
public class WorkerThread extends Thread{
public void run(){
try{
if(doSave())
state.saveClicked(getInstance());
}
catch ( Exception ex ) {
Message.showException( "Fehler beim Speichern der Daten.", ex );
}
mainFrame.getGlassPane().setVisible( false );
}
}
But now I have a new Problem: The button, which triggers this event is
also accesible via hot key. And if this hot key is used, no hourglass
cursor
is shown.
I also tested the event consumption of the glasspane. It doesn't work
too. This means, that If you click somwhere, while the hourglass cursor
shows up. This events are fired later, when the cursor disapears.
Please help.
Markus
--
tiscon AG
Infosystems
_______________________________
Markus Schwarz
Magirusstra�e 4
D-89129 Langenau
Phone ++ 49 - 7345 - 9669-17
Fax ++ 49 - 7345 - 9669-20
E-Mail m.schwarz@tiscon.de
WWW HTTP://www.tiscon.de
Technical Details
Message-ID:
<38476EC2.BFC44FC9@tiscon.de>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 111d45,2f693a0aff28f161,start X-Google-Attributes: gid111d45,public From: Markus Schwarz <m.schwarz@tiscon.de> Subject: Hourglass cursor, glasspane and keyboard hotkeys Date: 1999/12/03 Message-ID: <38476EC2.BFC44FC9@tiscon.de> X-Deja-AN: 556109158 Content-Transfer-Encoding: 8bit Organization: Another Netscape Collabra Server User X-Accept-Language: en Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing