Source Code : Swing Utilities getWindowAncestor

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Swing Utilities getWindowAncestor

    
/*
Code from Desktop Java Live Source

URL: http://www.sourcebeat.com/downloads/

*/



import javax.swing.*;
import java.awt.event.ActionEvent;

public class DialogBlockingExample {
    public static JPanel createPanel() {
        JPanel panel = new JPanel();

        JButton button = new JButton(new DialogAction(panel));
        panel.add(button);

        return panel;
    }

    private static class DialogAction extends AbstractAction {
        private JPanel panel;

        public DialogAction(JPanel panel) {
            super("Open Dialog");
            this.panel = panel;
        }

        public void actionPerformed(ActionEvent e) {
            JDialog dialog = new JDialog((JFrame) SwingUtilities.getWindowAncestor(panel), true);
            dialog.getContentPane().add(new JLabel("A Dialog"));
            dialog.setVisible(true);
            putValue(Action.NAME, "Dialog Already Shown");
        }
    }
    
    public static void main(String[] a){
      JFrame f = new JFrame();
      f.setDefaultCloseOperation(1);
      f.add(createPanel());
      f.pack();
      f.setVisible(true);
    } 

}

           
         
    
    
    
  

Thank with us