JXGlassBoxDemoPanel.java
上传用户:zhengdagz
上传日期:2014-03-06
资源大小:1956k
文件大小:4k
源码类别:

xml/soap/webservice

开发平台:

Java

  1. /*
  2.  * JXGlassBoxDemoPanel.java
  3.  *
  4.  * Created on April 18, 2005, 4:20 PM
  5.  */
  6. package org.jdesktop.demo.swingx;
  7. import java.awt.Component;
  8. import java.awt.Container;
  9. import java.awt.Point;
  10. import javax.swing.JLabel;
  11. import javax.swing.SwingUtilities;
  12. import org.jdesktop.demo.DemoPanel;
  13. import org.jdesktop.swingx.border.DropShadowBorder;
  14. /**
  15.  * Demonstrates the JXGlassBox component.
  16.  *
  17.  * @author  rbair
  18.  */
  19. public class JXGlassBoxDemoPanel extends DemoPanel {
  20.     
  21.     /** Creates new form JXGlassBoxDemoPanel */
  22.     public JXGlassBoxDemoPanel() {
  23.         setName("JXGlassBox Demo");
  24.         initComponents();
  25.     }
  26.     public String getHtmlDescription() {
  27.         return "<html>Click on the button to show the JXGlassBox, then click on the " +
  28.                 "glass box to dismiss it. This shows how a glass box can be used for a pop-up " +
  29.                 "message in your application.<br>This demo also showcases the DropShadowBorder.</html>";
  30.     }
  31.     public String getName() {
  32.         return "Glass Boxes";
  33.     }
  34.     /** This method is called from within the constructor to
  35.      * initialize the form.
  36.      * WARNING: Do NOT modify this code. The content of this method is
  37.      * always regenerated by the Form Editor.
  38.      */
  39.     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
  40.     private void initComponents() {
  41.         java.awt.GridBagConstraints gridBagConstraints;
  42.         jXGlassBox1 = new org.jdesktop.swingx.JXGlassBox();
  43.         jLabel1 = new javax.swing.JLabel();
  44.         showGlassBoxBtn = new javax.swing.JButton();
  45.         jXGlassBox1.setLayout(new java.awt.BorderLayout());
  46.         JLabel lbl = new JLabel("<html><i>Please click to dismiss...</i></html>");
  47.         jXGlassBox1.add(lbl);
  48.         jLabel1.setBackground(new java.awt.Color(255, 255, 255));
  49.         jLabel1.setText("<html><c><i>Click to hide this panel (ie, dismiss)</c></i></html>");
  50.         jLabel1.setOpaque(true);
  51.         jXGlassBox1.add(jLabel1, java.awt.BorderLayout.CENTER);
  52.         setLayout(new java.awt.GridBagLayout());
  53.         showGlassBoxBtn.setText("Make GlassBox Visible");
  54.         showGlassBoxBtn.addActionListener(new java.awt.event.ActionListener() {
  55.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  56.                 showGlassBoxBtnActionPerformed(evt);
  57.             }
  58.         });
  59.         gridBagConstraints = new java.awt.GridBagConstraints();
  60.         gridBagConstraints.gridx = 1;
  61.         gridBagConstraints.gridy = 1;
  62.         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
  63.         gridBagConstraints.weightx = 1.0;
  64.         gridBagConstraints.insets = new java.awt.Insets(0, 12, 11, 11);
  65.         add(showGlassBoxBtn, gridBagConstraints);
  66.     }
  67.     // </editor-fold>//GEN-END:initComponents
  68.     private void showGlassBoxBtnActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showGlassBoxBtnActionPerformed
  69.         Container glassPane = (Container)getRootPane().getGlassPane();
  70.         // Only allow one message box to be visible at a time so
  71.         // pop down any visible message boxes
  72.         Component glassPaneChildren[] = glassPane.getComponents();
  73.         for(int i = 0; i < glassPaneChildren.length; i++) {
  74.             glassPaneChildren[i].setVisible(false);
  75.             glassPane.remove(glassPaneChildren[i]);
  76.         }
  77.         Point p = SwingUtilities.convertPoint(this, showGlassBoxBtn.getX(), showGlassBoxBtn.getY(), null);
  78.         jXGlassBox1.setBorder(new DropShadowBorder());
  79.         jXGlassBox1.showOnGlassPane(glassPane, p.x, p.y);
  80.     }//GEN-LAST:event_showGlassBoxBtnActionPerformed
  81.     
  82.     
  83.     // Variables declaration - do not modify//GEN-BEGIN:variables
  84.     private javax.swing.JLabel jLabel1;
  85.     private org.jdesktop.swingx.JXGlassBox jXGlassBox1;
  86.     private javax.swing.JButton showGlassBoxBtn;
  87.     // End of variables declaration//GEN-END:variables
  88.     
  89. }