Example usage for javax.swing.event AncestorListener AncestorListener

List of usage examples for javax.swing.event AncestorListener AncestorListener

Introduction

In this page you can find the example usage for javax.swing.event AncestorListener AncestorListener.

Prototype

AncestorListener

Source Link

Usage

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("Ancestor Sampler");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    AncestorListener ancestorListener = new AncestorListener() {
        public void ancestorAdded(AncestorEvent ancestorEvent) {
            System.out.println("Added");
        }//w w  w .ja va 2  s . co  m

        public void ancestorMoved(AncestorEvent ancestorEvent) {
            System.out.println("Moved");
        }

        public void ancestorRemoved(AncestorEvent ancestorEvent) {
            System.out.println("Removed");
        }
    };
    f.getRootPane().addAncestorListener(ancestorListener);
    f.getRootPane().setVisible(false);
    f.getRootPane().setVisible(true);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Ancestor Sampler");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    AncestorListener ancestorListener = new AncestorListener() {
        public void ancestorAdded(AncestorEvent ancestorEvent) {
            System.out.println("Added");
        }//  w  w  w.  j  a  v a2s .co  m

        public void ancestorMoved(AncestorEvent ancestorEvent) {
            System.out.println("Moved");
        }

        public void ancestorRemoved(AncestorEvent ancestorEvent) {
            System.out.println("Removed");
        }
    };
    frame.getRootPane().addAncestorListener(ancestorListener);
    frame.setSize(300, 200);
    frame.setVisible(true);
    frame.getRootPane().setVisible(false);
    frame.getRootPane().setVisible(true);
}

From source file:AncestorSampler.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Ancestor Sampler");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    AncestorListener ancestorListener = new AncestorListener() {
        public void ancestorAdded(AncestorEvent ancestorEvent) {
            System.out.println("Added");
        }//from  w  w  w  .  ja v  a2 s  .  co  m

        public void ancestorMoved(AncestorEvent ancestorEvent) {
            System.out.println("Moved");
        }

        public void ancestorRemoved(AncestorEvent ancestorEvent) {
            System.out.println("Removed");
        }
    };
    JButton bn = new JButton();
    bn.addAncestorListener(ancestorListener);
    frame.add(bn);
    //frame.remove(bn);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    final JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();
    JButton b = new JButton("Hide for 5");
    ActionListener action = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            frame.setVisible(false);/*from w ww . j  av a  2s. c  om*/
            TimerTask task = new TimerTask() {
                public void run() {
                    frame.setVisible(true);
                }
            };
            Timer timer = new Timer();
            timer.schedule(task, 5000);
        }
    };
    b.addActionListener(action);
    AncestorListener ancestor = new AncestorListener() {
        public void ancestorAdded(AncestorEvent e) {
            System.out.println("Added");
            dumpInfo(e);
        }

        public void ancestorMoved(AncestorEvent e) {
            System.out.println("Moved");
            dumpInfo(e);
        }

        public void ancestorRemoved(AncestorEvent e) {
            System.out.println("Removed");
            dumpInfo(e);
        }

        private void dumpInfo(AncestorEvent e) {
            System.out.println("\tAncestor: " + name(e.getAncestor()));
            System.out.println("\tAncestorParent: " + name(e.getAncestorParent()));
            System.out.println("\tComponent: " + name(e.getComponent()));
        }

        private String name(Container c) {
            return (c == null) ? null : c.getName();
        }
    };
    b.addAncestorListener(ancestor);
    contentPane.add(b, BorderLayout.NORTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

private static JPanel createPanel() {
    JPanel panel = new JPanel();
    final JLabel label = new JLabel(new Date().toString());
    panel.add(label);//from  ww w .  j  ava 2 s. c om
    panel.addAncestorListener(new AncestorListener() {
        @Override
        public void ancestorAdded(AncestorEvent event) {
            // start animation
            label.setText(new Date().toString());
        }

        @Override
        public void ancestorRemoved(AncestorEvent event) {
            // stop animation
        }

        @Override
        public void ancestorMoved(AncestorEvent event) {
        }
    });
    return panel;
}

From source file:Main.java

public static void focusOnOpen(final JComponent component) {
    /*/*from   ww w. j  av  a2s .  co  m*/
    final Window window = SwingUtilities.getWindowAncestor(component);
    if (window != null)
      window.addWindowListener(new WindowAdapter() {
    public void windowOpened(WindowEvent e) {
      component.requestFocus();
      window.removeWindowListener(this);
    }
      });
     */

    component.addAncestorListener(new AncestorListener() {
        public void ancestorAdded(AncestorEvent event) {
            component.requestFocusInWindow();
            component.removeAncestorListener(this);
        }

        public void ancestorRemoved(AncestorEvent event) {
        }

        public void ancestorMoved(AncestorEvent event) {
        }
    });
}

From source file:com.digitalgeneralists.assurance.ui.components.ScanHistoryPanel.java

private void initializeComponent() {
    if (!this.initialized) {
        GridBagLayout gridbag = new GridBagLayout();
        this.setLayout(gridbag);

        GridBagConstraints existingScansPanelConstraints = new GridBagConstraints();
        existingScansPanelConstraints.anchor = GridBagConstraints.WEST;
        existingScansPanelConstraints.fill = GridBagConstraints.BOTH;
        existingScansPanelConstraints.gridx = 0;
        existingScansPanelConstraints.gridy = 0;
        existingScansPanelConstraints.weightx = 1.0;
        existingScansPanelConstraints.weighty = 1.0;
        existingScansPanelConstraints.gridheight = 1;
        existingScansPanelConstraints.gridwidth = 1;
        existingScansPanelConstraints.insets = new Insets(0, 0, 0, 0);

        this.existingScansListPanel = new ListInputPanel<Scan>(this, this, true, true);
        this.add(this.existingScansListPanel, existingScansPanelConstraints);

        this.addAncestorListener(new AncestorListener() {
            public void ancestorAdded(AncestorEvent event) {
                applicationDelegate.addEventObserver(ScanCompletedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(ScansLoadedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(ScanDeletedEvent.class,
                        (IEventObserver) event.getSource());

                applicationDelegate.loadScans();
            }/*from   w ww  . j a  v  a  2s  .  co m*/

            public void ancestorRemoved(AncestorEvent event) {
                applicationDelegate.removeEventObserver(ScanCompletedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(ScansLoadedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(ScanDeletedEvent.class,
                        (IEventObserver) event.getSource());
            }

            public void ancestorMoved(AncestorEvent event) {
            }
        });

        this.initialized = true;
    }
}

From source file:com.igormaznitsa.sciareto.ui.editors.mmeditors.NoteEditor.java

public NoteEditor(@Nonnull final String text) {
    initComponents();/*from  www . j a v a 2  s .  com*/
    this.setPreferredSize(new Dimension(640, 480));
    this.editorPane.setText(text);
    this.addAncestorListener(new AncestorListener() {
        @Override
        public void ancestorAdded(@Nonnull final AncestorEvent event) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    editorPane.requestFocusInWindow();
                    updateCaretPos();
                }
            });
        }

        @Override
        public void ancestorRemoved(@Nonnull final AncestorEvent event) {
        }

        @Override
        public void ancestorMoved(@Nonnull final AncestorEvent event) {
        }
    });

    this.editorPane.addCaretListener(new CaretListener() {
        @Override
        public void caretUpdate(@Nonnull final CaretEvent e) {
            updateCaretPos();
        }
    });

    this.wrapping = Wrapping.NONE;

    updateBottomPanel();
}

From source file:com.moss.bdbadmin.client.ui.BdbAdminClient.java

public BdbAdminClient(HttpClient httpClient, JFrame window, File configPath, ProxyFactory proxyFactory) {

    this.httpClient = httpClient;
    this.ancestor = window;
    this.configPath = configPath;
    this.proxyFactory = proxyFactory;

    try {/* www  .ja v a2s.  co  m*/
        configJaxbContext = JAXBContext.newInstance(ServiceConfig.class);
    } catch (JAXBException ex) {
        throw new RuntimeException(ex);
    }

    JMenuItem newServiceItem = new JMenuItem("New Service");
    newServiceItem.setAction(new NewServiceAction());

    JMenu fileMenu = new JMenu("File");
    fileMenu.add(newServiceItem);

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(fileMenu);

    window.setJMenuBar(menuBar);
    window.setIconImage(new ImageIcon(this.getClass().getClassLoader().getResource("service.gif")).getImage());

    this.root = new DefaultMutableTreeNode();
    this.model = new DefaultTreeModel(root);
    getTree().setModel(model);
    getTree().setShowsRootHandles(true);
    getTree().setRootVisible(false);
    getTree().setCellRenderer(new Renderer());
    getTree().getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    getTree().getSelectionModel().addTreeSelectionListener(new SelectionListener());
    getTree().addMouseListener(new ContextMenuHandler());

    addAncestorListener(new AncestorListener() {
        public void ancestorAdded(AncestorEvent event) {
            loadConfig();
        }

        public void ancestorMoved(AncestorEvent event) {
        }

        public void ancestorRemoved(AncestorEvent event) {
        }
    });
}

From source file:com.digitalgeneralists.assurance.ui.components.ResultsPanel.java

private void initializeComponent() {
    if (!this.initialized) {
        GridBagLayout gridbag = new GridBagLayout();
        this.setLayout(gridbag);

        ((DefaultTableCellRenderer) resultsTable.getTableHeader().getDefaultRenderer())
                .setHorizontalAlignment(JLabel.CENTER);
        this.resultsTable.setRowHeight(150);

        ListSelectionModel selectionModel = this.resultsTable.getSelectionModel();

        selectionModel.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                applicationDelegate.fireEvent(new SetScanResultsMenuStateEvent(false));
                resultsTable.editCellAt(resultsTable.getSelectedRow(), 0);
            }/*www.j a va 2 s. c om*/
        });

        GridBagConstraints resultsLabelConstraints = new GridBagConstraints();
        resultsLabelConstraints.anchor = GridBagConstraints.WEST;
        resultsLabelConstraints.fill = GridBagConstraints.BOTH;
        resultsLabelConstraints.gridx = 0;
        resultsLabelConstraints.gridy = 0;
        resultsLabelConstraints.weightx = 1.0;
        resultsLabelConstraints.weighty = 0.1;
        resultsLabelConstraints.gridheight = 1;
        resultsLabelConstraints.gridwidth = 1;
        resultsLabelConstraints.insets = new Insets(5, 5, 5, 5);

        this.progressIndicatorConstraints.anchor = GridBagConstraints.WEST;
        this.progressIndicatorConstraints.fill = GridBagConstraints.BOTH;
        this.progressIndicatorConstraints.gridx = 0;
        this.progressIndicatorConstraints.gridy = 1;
        this.progressIndicatorConstraints.weightx = 1.0;
        this.progressIndicatorConstraints.weighty = 0.1;
        this.progressIndicatorConstraints.gridheight = 1;
        this.progressIndicatorConstraints.gridwidth = 1;
        this.progressIndicatorConstraints.insets = new Insets(5, 5, 5, 5);

        this.progressIndicator.setIndeterminate(true);

        this.resultsListConstraints.anchor = GridBagConstraints.WEST;
        this.resultsListConstraints.fill = GridBagConstraints.BOTH;
        this.resultsListConstraints.gridx = 0;
        this.resultsListConstraints.gridy = 2;
        this.resultsListConstraints.weightx = 1.0;
        this.resultsListConstraints.weighty = 0.9;
        this.resultsListConstraints.gridheight = 1;
        this.resultsListConstraints.gridwidth = 1;
        this.resultsListConstraints.insets = new Insets(5, 5, 5, 5);

        this.add(this.resultsLabel, resultsLabelConstraints);
        this.add(this.resultsScrollPane, this.resultsListConstraints);

        this.addAncestorListener(new AncestorListener() {
            public void ancestorAdded(AncestorEvent event) {
                resultsTable.setDefaultRenderer(ComparisonResult.class, comparisonResultListRenderer);
                resultsTable.setDefaultEditor(ComparisonResult.class, comparisonResultListRenderer);

                applicationDelegate.addEventObserver(ScanStartedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(ComparisonResultAddedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(ScanResultsLoadedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(SelectedScanChangedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(ScanCompletedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(ScanProgressEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(ResultMergeCompletedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(ScanMergeStartedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(ScanMergeProgressEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(ScanMergeCompletedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(DeletedItemRestoreCompletedEvent.class,
                        (IEventObserver) event.getSource());
            }

            public void ancestorRemoved(AncestorEvent event) {
                applicationDelegate.removeEventObserver(ScanStartedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(ComparisonResultAddedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(ScanResultsLoadedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(SelectedScanChangedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(ScanCompletedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(ScanProgressEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(ResultMergeCompletedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(ScanMergeStartedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(ScanMergeProgressEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(ScanMergeCompletedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(DeletedItemRestoreCompletedEvent.class,
                        (IEventObserver) event.getSource());
            }

            public void ancestorMoved(AncestorEvent event) {
            }
        });

        this.initialized = true;
    }
}