Set the Cursor for Anactive Frames
- From: Volker Raum <Volker.Raum@xxxxxxxxx>
- Date: Mon, 26 Feb 2007 16:16:48 +0100
Hi,
my Application got a Main Frame (JFrame).
Sometimes i open up a Dialog. While the Dialog is open i would like to have a
"Wait-Cursor" for the inactive Frame. (Dialogs parent is the Frame).
Is there a way to do that.
Anyone can help?
My litte example doesn't work.
package framecursor;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class FrameCursorMain extends JFrame
{
JPanel mainPanel = new JPanel() ;
JButton openButton = new JButton("Open") ;
public static void main(String[] args)
{
new FrameCursorMain() ;
}
public FrameCursorMain()
{
this.setContentPane(mainPanel) ;
mainPanel.add(openButton) ;
openButton.addActionListener( new DialogListener(this)) ;
this.setSize(300,200) ;
// Show The Frame
this.setVisible(true) ;
}
}
class DialogListener implements ActionListener
{
JFrame parentFrame = null ;
public DialogListener(JFrame parentFrame)
{
super();
this.parentFrame = parentFrame;
}
public void actionPerformed(ActionEvent e)
{
// Define the Dialog
JDialog dlg = new JDialog( parentFrame, "TestDialog", true) ;
dlg.setSize(200,100) ;
// Set the Cursor of the Frame and open the Dialog
parentFrame.setCursor( Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR) ) ;
dlg.setVisible(true) ;
// DLG was closed
// Reset the Cursor of the Frame
parentFrame.setCursor( Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)) ;
}
}
.
- Prev by Date: Re: TrayIcon with PopupMenu or JPopupMenu ?
- Next by Date: Handling exceptions in SwingWorker
- Previous by thread: Creating JTextArea on main window of app ?
- Next by thread: Handling exceptions in SwingWorker
- Index(es):