I want the user to click a button to start a background thread.
While the thread is processing, I want two things to happen:
1) WAIT_CURSOR should be displayed.
2) The application should not respond to mouse events.
According to setCursor documentation "This cursor image is displayed when the contains method for this component returns true for the current cursor location, and this Component is displayed, displayed, and available."
I want my application to be disabled while this background thread is processing.
Any ideas on how to get the required functionality?
import java.awt.Component; import java.awt.Cursor; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.SwingUtilities; public class WaitCursor extends JFrame { private static final long serialVersionUID = 1L; public WaitCursor() { setResizable(false); setName(getClass().getSimpleName()); setTitle("My Frame"); setSize(300, 300); getContentPane().add(new MyButtonPanel()); } private class MyButtonPanel extends JPanel { private static final long serialVersionUID = 1L; public MyButtonPanel() { JButton btnStart = new JButton("Start"); btnStart.addActionListener(new BtnStartActionListener()); add(btnStart); } private class BtnStartActionListener implements ActionListener { public void actionPerformed(ActionEvent e) {
source share