removing mouse events/controls from swing components with glasspane

Posted by Deger on Stack Overflow See other posts from Stack Overflow or by Deger
Published on 2010-02-17T12:57:37Z Indexed on 2010/05/12 17:04 UTC
Read the original article Hit count: 231

Filed under:
|
|

Hi all, I have a client-server application and i am using swing in the client side. My swing client has one main window (jframe) and lots of panels, toolbars and menubar in it. I want to remove all client action/mouse events (or simply grab and do nothing) while client is waiting response from server by means of glasssPane. Here is the code i wrote:

private final static MouseAdapter mouseAdapter = new MouseAdapter() 

{ public void mouseClicked(MouseEvent e) { System.out.println("MouseClicked..!"); } }; private static Cursor WAIT_CURSOR = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); private static Cursor DEFAULT_CURSOR = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);

and

public static void startWaitCursor(JComponent comp)

{ MainWindow root = ((MainWindow) comp.getTopLevelAncestor());

root.getGlassPane().setCursor(WAIT_CURSOR); root.getGlassPane().addMouseListener(mouseAdapter); root.getGlassPane().setVisible(true); }

public static void stopWaitCursor(JComponent comp) {
MainWindow root = ((MainWindow) comp.getTopLevelAncestor());

root.getGlassPane().setCursor(DEFAULT_CURSOR); root.getGlassPane().setVisible(false); }

but i am not able to manage the grab mouse events. Changing cursors at the glassPane is working fine but either i am not able to add mouseAdapter or am not able to make glasssPane become to the top level component.

Any idea?

Thanks.

© Stack Overflow or respective owner

Related posts about swing

Related posts about glasspane