JPanel overlay which grabs all MouseEvents

Hi all.

I'm getting stuck with an OverlayLayout and a transparent JPanel.

What I have is a JPanel with several components on it (Textfields, Comboboxes, ..)

In the running application I need to be able to re-arrange the components using

drag & drop but this feature can be disabled so the UI behaves like every other you know.

(You can think of this as a minimalistic GUI designer).

My approach was to place another (transparent) JPanel on top of it using OverlayLayout to

be able to drag ghost copies of my components around with the mouse.

This panel can be switched invisible so dragging is disabled.

This works for components which do not react on mouse events for themselves

(JLabels, ..) but not for textfields.

What I would need is a transparent layer which is able to graball MouseEvents so the

components on the underlying panel will not receive them (textfields don't get the focus, buttons don't get clicked, ...).

Any help really appreciated.

Kind regards

Carsten

[1091 byte] By [C.Paschilkea] at [2007-10-2 10:46:05]
# 1
Instead of dragging a real component, you could just drag a rendered version of the component. Or create yourself images of each component and add them to a label then drag the label around. Then when you drop the image you replace it with a real component.
camickra at 2007-7-13 2:58:43 > top of Java-index,Desktop,Core GUI APIs...
# 2

You can use a glass pane to intercept all the events. Just try to delete "Edit Me" from this text box!

package mypackage;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class GlassPanelTest extends JFrame {

public GlassPanelTest() {

super("Glass Panel Test");

setBounds(10, 10, 380, 200);

Container contentPane = getContentPane();

contentPane.add(new JTextField("Edit Me"));

Component glassPane = getGlassPane();

glassPane.setVisible(true);

glassPane.addMouseListener(new MouseAdapter() {

public void mousePressed(MouseEvent _e) {

System.out.println("caught by the glass pane");

}

});

}

public static void main(String[] args) {

GlassPanelTest app = new GlassPanelTest();

app.setVisible(true);

}

}

C_Walkera at 2007-7-13 2:58:43 > top of Java-index,Desktop,Core GUI APIs...
# 3
The idea is good but the problem is that the area where those drag & drop operations will take place is a JPanel embedded in a more complex layout.Modifying the glasspane of the JFrame would result in grabbing mouse events on all the other panels included in my layout.
C.Paschilkea at 2007-7-13 2:58:43 > top of Java-index,Desktop,Core GUI APIs...
# 4
No one? Where are the Swing gurus?
C.Paschilkea at 2007-7-13 2:58:43 > top of Java-index,Desktop,Core GUI APIs...