Demonstrate use of GlassPane : GlassPane « Swing JFC « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java » Swing JFC » GlassPaneScreenshots 
Demonstrate use of GlassPane
Demonstrate use of GlassPane
 

import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/*
 * Demonstrate use of GlassPane in JWindow & friends. Buttons enable/disable it.
 * @author Eckstein et al, in the O'Reilly book "Java Swing"
 */
public class GlassExample {

  /** Construct a Splash screen with the given image */
  public static void main(String[] args) {
    JFrame f = new JFrame("GlassPane");

    final JPanel p1 = new JPanel();
    p1.add(new JLabel("GlassPane Example"));
    JButton show = new JButton("Show");
    p1.add(show);
    p1.add(new JButton("No-op"));
    f.getContentPane().add(p1);

    final JPanel glass = (JPanelf.getGlassPane();

    glass.setVisible(true);
    glass.setLayout(new GridBagLayout());
    JButton glassButton = new JButton("Hide");
    glass.add(glassButton);

    f.setSize(15080);
    f.setVisible(true);

    boolean debug = false;
    if (debug) {
      System.out.println("Button is " + glassButton);
      System.out.println("GlassPane is " + glass);
    }

    // Add actions to the buttons...

    // show button (re-)shows the glass pane.
    show.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        glass.setVisible(true);
        p1.repaint();
      }
    });
    // hide button hides the Glass Pane to show what's under.
    glassButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        glass.setVisible(false);
        p1.repaint();
      }
    });
  }

}




           
         
  
Related examples in the same category
1.Show how a glass pane can be used to block mouse (and key!) eventsShow how a glass pane can be used to block mouse (and key!) events
2.Paint on glass pane
3.Block mouse and key events in an application
4.Replace existing GlassPane
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.