@@ -0,0 +1,3211 @@
+//-----------------------------------------------------------------------//%0A//                                                                       //%0A//                  T e s t C o m p o n e n t E v e n t                  //%0A//                                                                       //%0A//  Copyright (C) Herve Bitteur 2000-2006. All rights reserved.          //%0A//  This software is released under the terms of the GNU General Public  //%0A//  License. Please contact the author at herve.bitteur@laposte.net      //%0A//  to report bugs & suggestions.                                        //%0A//-----------------------------------------------------------------------//%0A%0Apackage omr.ui;%0A%0Aimport java.awt.*;%0Aimport java.awt.event.*;%0Aimport javax.swing.*;%0Aimport javax.swing.event.*;%0A%0Apublic class TestComponentEvent%0A        extends ComponentAdapter%0A        implements ChangeListener%0A%7B%0A    JFrame frame = new JFrame(getClass().getName().toString());%0A    JTabbedPane tabbedPane = new JTabbedPane();%0A    JButton button = new JButton(new ToggleAction());%0A    %0A    public static void main (String... args)%0A    %7B%0A        new TestComponentEvent().play();%0A    %7D%0A%0A    public void play ()%0A    %7B%0A        frame.setName(%22LaFrame%22);%0A        frame.addComponentListener(this);%0A        Container pane = frame.getContentPane();%0A        pane.setLayout(new BorderLayout());%0A%0A        button.setText(%22Toggle%22);%0A        button.setName(%22LeBouton%22);%0A        pane.add(button, BorderLayout.NORTH);%0A        %0A        tabbedPane.setName(%22LeTabbedPane%22);%0A        pane.add(tabbedPane, BorderLayout.CENTER);%0A        tabbedPane.addComponentListener(this);%0A        tabbedPane.addChangeListener(this);%0A        %0A        for (int i = 0; i %3C 5; i++) %7B%0A            createTab(i);%0A        %7D%0A%0A        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);%0A        frame.pack();%0A        frame.setLocation(100, 100);%0A        frame.setSize(300, 120);%0A        frame.setVisible(true);%0A        %0A        System.out.println(%22**** Frame shown ****%22);%0A    %7D%0A    %0A    private void createTab (int index)%0A    %7B%0A        JPanel tab = new JPanel();%0A        tab.setName(%22Tab#%22 + index);%0A        tab.addComponentListener(this);%0A        tab.add(new JLabel(%22Texte de %22 + tab.getName()));%0A        tabbedPane.addTab(tab.getName(), tab);%0A    %7D%0A    %0A    class ToggleAction%0A            extends AbstractAction%0A    %7B%0A        public void actionPerformed(ActionEvent e) %7B%0A            tabbedPane.setVisible(!tabbedPane.isVisible());%0A        %7D%0A    %7D%0A%0A    public void componentShown(ComponentEvent e) %7B%0A        System.out.println(%22Shown%22 + %22 %22 + e.getComponent().getName());%0A        if (e.getComponent() == tabbedPane) %7B%0A            System.out.println(%22Forcing selection to tab %22 + tabbedPane.getSelectedIndex());%0A            tabbedPane.setSelectedIndex(tabbedPane.getSelectedIndex());%0A        %7D%0A    %7D%0A%0A    public void componentHidden(ComponentEvent e) %7B%0A        System.out.println(%22Hidden%22 + %22 %22 + e.getComponent().getName());%0A    %7D%0A%0A    public void stateChanged(ChangeEvent e) %7B%0A        // This is for tabbed pane%0A        System.out.println(%22Changed %22 + e.getSource().getClass().getName() %0A        + %22 to %22 + tabbedPane.getTitleAt(tabbedPane.getSelectedIndex()));%0A    %7D%0A%7D%0A

Test of events originated from components