Results 1 to 5 of 5

Thread: What are the Glass Pane in Java?

  1. #1
    Join Date
    Aug 2006
    Posts
    122

    What are the Glass Pane in Java?

    Hi friends,
    I have done some basic programs in Java, but I never heard about the glass pane. I have started doing the Java from last month and you can consider me as a beginner. Since, you guys helped me a lot last time, I thought that this is perfect place to post. So please explain me what are the Glass Pane in Java.?? Any related coding would be grateful.
    Extremely Thanks for the last time and hoping same this time.!
    In the end, we will remember not the words of our enemies, but the silence of our friends.
    -Martin Luther King Jr.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: What are the Glass Pane in Java?

    The glass pane is one type of the Root Panes. The glass pane is hidden by default. You should know about the Root Panes in Java before going to the glass pane. You can do your work in Swing with the JRootPane of a JFrame, JDialog, JWindow, JApplet, or JInternalFrame class. The root pane can then layer components with the help of a JLayeredPane in such a way that tooltip text and pop-up menus will always appear above their associated components. Using Top-Level Containers tells you the basics of using root panes. A root pane has following four types :
    • The glass pane.
    • The content pane.
    • The layered pane.
    • The optional menu bar.

  3. #3
    Join Date
    Mar 2008
    Posts
    672

    Re: What are the Glass Pane in Java?

    Using the glass pane is useful, when you need to catch events or paint over an area that already contains one or more components. Normally the application that demonstrates glass pane features contains a check box. This check box lets you set whether the glass pane is "visible". Also remember that the glass pane blocks all input events from reaching the components in the content pane. The glass pane is hidden by default. If you make the glass pane visible, then it's like a sheet of glass over all the other parts of the root pane because it is completely transparent.

  4. #4
    Join Date
    Mar 2008
    Posts
    349

    Re: What are the Glass Pane in Java?

    I have provided you with an example of the Glass Pane in Java. The following is the code for the same :
    Code:
    package components;
    
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.MouseEvent;
    import javax.swing.event.MouseInputAdapter;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    
    public class GlassPaneDemo {
        static private MyGlassPane myGlassPane;
    
        private static void createAndShowGUI() {
            JFrame frame = new JFrame("TrialGlassPane");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            JCheckBox changeButton =
                    new JCheckBox("Glass Pane \"visible\"");
            changeButton.setSelected(false);
            
            Container contentPane = frame.getContentPane();
            contentPane.setLayout(new FlowLayout());
            contentPane.add(changeButton);
            contentPane.add(new JButton("Button 1"));
            contentPane.add(new JButton("Button 2"));
    
            JMenuBar menuBar = new JMenuBar();
            JMenu menu = new JMenu("Menu");
            menu.add(new JMenuItem("Keep Watching"));
            menuBar.add(menu);
            frame.setJMenuBar(menuBar);
    
            myGlassPane = new MyGlassPane(changeButton, menuBar,
                                          frame.getContentPane());
            changeButton.addItemListener(myGlassPane);
            frame.setGlassPane(myGlassPane);
    
            frame.pack();
            frame.setVisible(true);
        }
    
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
    }

  5. #5
    Join Date
    Nov 2008
    Posts
    996

    Re: What are the Glass Pane in Java?

    Also while writing the code of the Glass Pane you would have to provide our own glass pane so that it can paint. I have given you sample of code that explains how to provide our own glass pane :
    Code:
    class MyGlassPane extends JComponent
                      implements ItemListener {
        Point point;
    
        public void itemStateChanged(ItemEvent ie) {
            setVisible(ie.getStateChange() == ItemEvent.SELECTED);
        }
    
        protected void paintComponent(Graphics g) {
            if (point != null) {
                g.setColor(Color.blue);
                g.fillOval(point.x - 20, point.y - 20, 30, 30);
            }
        }
    
        public void setPoint(Point p) {
            point = p;
        }
    
        public MyGlassPane(AbstractButton aButton,
                           JMenuBar menuBar,
                           Container contentPane) {
            CBListener listener = new CBListener(aButton, menuBar,
                                                 this, contentPane);
            addMouseListener(listener);
            addMouseMotionListener(listener);
        }
    }

Similar Threads

  1. Preview Pane not functioning in windows 7
    By RAJni-Gandha in forum Windows Software
    Replies: 3
    Last Post: 09-01-2011, 07:43 PM
  2. How to tweak the navigation pane of explorer
    By Indivar in forum Operating Systems
    Replies: 5
    Last Post: 10-12-2010, 11:55 PM
  3. Missing folders pane
    By prakashseth in forum Windows Vista Mail
    Replies: 2
    Last Post: 27-10-2010, 11:09 PM
  4. Embedding v/s Three-Pane Environment
    By Ephraim in forum Technology & Internet
    Replies: 3
    Last Post: 27-03-2009, 08:50 AM
  5. No Preview Pane Option in vista
    By Gopesh in forum Operating Systems
    Replies: 3
    Last Post: 21-02-2009, 05:46 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,520,775.20514 seconds with 16 queries