Want a GlassPane for a JPanel! Or do I go MDI?

Hello,
We have an Swing application that has been using to the
the GlassPane in JFrame. Since the application used
the complete JFrame, it was ok.
The problem is the new release, requires the effect we
are using the GlassPane to be localized to a JPanel.
We are using a gridbaglayout that has other JPanel doing
other activities.
The problem is that the GlassPane is in the JFrame.
So it covers all the other JPanels, when it's used.
At present the only solution I have come up with is to
go MDI and have multple JFrames. And redo the entire
application and layout as a MDI.
Is there anyway, to just localize a GlassPane to a single
JPanel.
Or is the solution MDI approach...
thanks for your feedback..
larry

Here is an example I made :
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class OverlayPanel extends JPanel {
     private GlassPanel glassPanel;
     public JCheckBox check;
     public OverlayPanel() {
          setLayout(new OverlayLayout(this));
          glassPanel = new GlassPanel();
          add(glassPanel);
          add(new SubPanel());
          setPreferredSize(new Dimension(500,500));
          check = new JCheckBox("Enable glass pane for the panel");
          check.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                    glassPanel.setVisible(((JCheckBox)e.getSource()).isSelected());
     static class SubPanel extends JPanel {
          Point p = new Point(0,0);
          public SubPanel() {
               setBackground(Color.white);
               MouseHandler mh = new MouseHandler();
               addMouseListener(mh);
               addMouseMotionListener(mh);
          final class MouseHandler extends MouseInputAdapter {
               public void mousePressed(MouseEvent e) {
                    p.setLocation(e.getPoint());
                    repaint();
               public void mouseDragged(MouseEvent e) {
                    p.setLocation(e.getPoint());
                    repaint();
          public void paintComponent(Graphics g) {
               super.paintComponent(g);
               g.setColor(Color.red);
               g.fillOval(p.x-10,p.y-10,20,20);
     static class GlassPanel extends JPanel {
          Point p = new Point(0,0);
          public GlassPanel() {
               setOpaque(false);
               MouseHandler mh = new MouseHandler();
               addMouseListener(mh);
               addMouseMotionListener(mh);
               setVisible(false);
          final class MouseHandler extends MouseInputAdapter {
               public void mousePressed(MouseEvent e) {
                    p.setLocation(e.getPoint());
                    repaint();
               public void mouseDragged(MouseEvent e) {
                    p.setLocation(e.getPoint());
                    repaint();
          public void paintComponent(Graphics g) {
               g.setColor(Color.green);
               g.fillOval(p.x-10,p.y-10,20,20);
     public static void main(String[] args) {
          JFrame f = new JFrame("Test panel glass pane");
          OverlayPanel p = new OverlayPanel();
          f.getContentPane().add(p, BorderLayout.CENTER);
          f.getContentPane().add(p.check, BorderLayout.SOUTH);
          f.pack();
          f.setVisible(true);
}Denis

Similar Messages

Maybe you are looking for