/*
* Copyright (c) 2009, Paul Merlin. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.swing.on.steroids.swing.components;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.lang.reflect.InvocationTargetException;
import javax.swing.JFrame;
public class JFrameDisposeSample
extends javax.swing.JFrame
{
/** Creates new form TestJFrameDispose */
public JFrameDisposeSample()
{
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings( "unchecked" )
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Close me");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addContainerGap(330, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addContainerGap(271, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* @param args the command line arguments
*/
public static void main( String args[] )
throws InterruptedException, InvocationTargetException
{
java.awt.EventQueue.invokeAndWait( new Runnable()
{
@Override
public void run()
{
final JFrame frame = new JFrameDisposeSample();
frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );
frame.setVisible( true );
frame.addWindowListener( new WindowAdapter()
{
@Override
public void windowClosing( WindowEvent e )
{
System.out.println( "closing : displayable: " + frame.isDisplayable() );
frame.dispose();
System.out.println( "disposed : displayable: " + frame.isDisplayable() );
}
@Override
public void windowClosed( WindowEvent e )
{
System.out.println( "closed : displayable: " + frame.isDisplayable() );
frame.setVisible( true );
System.out.println( "setVisible(true) : displayable: " + frame.isDisplayable() );
}
} );
}
} );
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLabel1;
// End of variables declaration//GEN-END:variables
}