Example usage for java.awt.event ContainerListener ContainerListener

List of usage examples for java.awt.event ContainerListener ContainerListener

Introduction

In this page you can find the example usage for java.awt.event ContainerListener ContainerListener.

Prototype

ContainerListener

Source Link

Usage

From source file:Main.java

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

    JPanel buttonPanel = new JPanel();
    buttonPanel.addContainerListener(new ContainerListener() {
        public void componentAdded(ContainerEvent e) {
            displayMessage(" added to ", e);
        }//from w ww  . ja  va 2  s  . c o  m

        public void componentRemoved(ContainerEvent e) {
            displayMessage(" removed from ", e);
        }

        void displayMessage(String action, ContainerEvent e) {
            System.out.println(((JButton) e.getChild()).getText() + " was" + action
                    + e.getContainer().getClass().getName());
        }
    });
    buttonPanel.add(new JButton("A"));

    frame.add(buttonPanel);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

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

    JPanel buttonPanel = new JPanel(true);
    buttonPanel.addContainerListener(new ContainerListener() {
        public void componentAdded(ContainerEvent e) {
            displayMessage(" added to ", e);
        }/*from  w  ww.j a  v  a  2  s.co  m*/

        public void componentRemoved(ContainerEvent e) {
            displayMessage(" removed from ", e);
        }

        void displayMessage(String action, ContainerEvent e) {
            System.out.println(((JButton) e.getChild()).getText() + " was" + action
                    + e.getContainer().getClass().getName());
        }
    });
    buttonPanel.add(new JButton("A"));

    frame.add(buttonPanel);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:UsingContainerListener.java

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

    JPanel buttonPanel = new JPanel();
    buttonPanel.addContainerListener(new ContainerListener() {

        public void componentAdded(ContainerEvent e) {
            displayMessage(" added to ", e);
        }/* w ww .  j a v a2 s.co m*/

        public void componentRemoved(ContainerEvent e) {
            displayMessage(" removed from ", e);
        }

        void displayMessage(String action, ContainerEvent e) {
            System.out.println(((JButton) e.getChild()).getText() + " was" + action
                    + e.getContainer().getClass().getName());
        }
    });
    buttonPanel.add(new JButton("A"));

    frame.add(buttonPanel);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:ContainerTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();

    ContainerListener cont = new ContainerListener() {
        ActionListener listener = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.out.println("Selected: " + e.getActionCommand());
            }//from   w w w  .j ava2s  . c  o m
        };

        public void componentAdded(ContainerEvent e) {
            Component c = e.getChild();
            if (c instanceof JButton) {
                JButton b = (JButton) c;
                b.addActionListener(listener);
            }
        }

        public void componentRemoved(ContainerEvent e) {
            Component c = e.getChild();
            if (c instanceof JButton) {
                JButton b = (JButton) c;
                b.removeActionListener(listener);
            }
        }
    };

    contentPane.addContainerListener(cont);

    contentPane.setLayout(new GridLayout(3, 2));
    contentPane.add(new JButton("First"));
    contentPane.add(new JButton("Second"));
    contentPane.add(new JButton("Third"));
    contentPane.add(new JButton("Fourth"));
    contentPane.add(new JButton("Fifth"));

    frame.setSize(300, 200);
    frame.show();
}

From source file:the.bytecode.club.bytecodeviewer.gui.WorkPane.java

public WorkPane(final FileChangeNotifier fcn) {
    super("WorkPanel");
    setTitle("Work Space");

    this.tabs = new JTabbedPane();
    this.fcn = fcn;

    getContentPane().setLayout(new BorderLayout());

    getContentPane().add(tabs, BorderLayout.CENTER);

    buttonPanel = new JPanel(new FlowLayout());

    refreshClass = new JButton("Refresh");
    refreshClass.addActionListener(this);

    buttonPanel.add(refreshClass);//ww w. j a v a  2 s. c  o m

    //Xposed 
    generateXposedClass = new JButton("Generate Xposed Module");
    generateXposedClass.addActionListener(this);
    buttonPanel.add(generateXposedClass);

    buttonPanel.setVisible(false);

    getContentPane().add(buttonPanel, BorderLayout.SOUTH);

    tabs.addContainerListener(new ContainerListener() {

        @Override
        public void componentAdded(final ContainerEvent e) {
        }

        @Override
        public void componentRemoved(final ContainerEvent e) {
            final Component c = e.getChild();
            if (c instanceof ClassViewer) {
                ClassViewer cv = (ClassViewer) c;
                workingOn.remove(cv.container + "$" + cv.name);
            }
            if (c instanceof FileViewer) {
                FileViewer fv = (FileViewer) c;
                workingOn.remove(fv.container + "$" + fv.name);
            }
        }

    });
    tabs.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(final ChangeEvent arg0) {
            buttonPanel.setVisible(tabs.getSelectedIndex() != -1);
        }
    });

    this.setVisible(true);

}

From source file:com.diversityarrays.dal.server.SqlDialog.java

SqlDialog(JFrame owner, SqlDalDatabase db) {
    super(owner, "SQL", ModalityType.MODELESS);

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    this.database = db;

    runner = new DefaultBackgroundRunner("SQL Command", this);
    setGlassPane(runner.getBlockingPane());

    sqlCommands.setFont(GuiUtil.createMonospacedFont(12));

    includeHeadingsInCopy.addItemListener(new ItemListener() {
        @Override/*from  w  w w .j  ava  2  s .c o  m*/
        public void itemStateChanged(ItemEvent e) {
            boolean b = includeHeadingsInCopy.isSelected();
            for (int n = tabbedPane.getTabCount(); --n >= 0;) {
                Component c = tabbedPane.getComponentAt(n);
                if (c instanceof SqlResultsPanel) {
                    ((SqlResultsPanel) c).setIncludeHeadings(b);
                }
            }
        }
    });

    tabbedPane.addContainerListener(new ContainerListener() {
        @Override
        public void componentRemoved(ContainerEvent e) {
            updateClosePanelAction();
        }

        @Override
        public void componentAdded(ContainerEvent e) {
            updateClosePanelAction();
        }
    });
    updateClosePanelAction();

    Box buttons = Box.createHorizontalBox();
    buttons.add(Box.createHorizontalStrut(10));
    buttons.add(new JButton(runAction));
    buttons.add(Box.createHorizontalStrut(20));
    buttons.add(new JButton(closePanelAction));

    buttons.add(Box.createHorizontalGlue());
    buttons.add(includeHeadingsInCopy);
    buttons.add(Box.createHorizontalStrut(10));
    buttons.add(new JButton(helpAction));
    buttons.add(Box.createHorizontalStrut(10));

    JPanel top = new JPanel(new BorderLayout());
    top.add(BorderLayout.CENTER, new JScrollPane(sqlCommands));
    top.add(BorderLayout.SOUTH, buttons);

    final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, top, tabbedPane);
    splitPane.setResizeWeight(0.25);

    setContentPane(splitPane);

    pack();

    setSize(800, 600);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            splitPane.setDividerLocation(0.25);
            removeWindowListener(this);
        }

    });
}

From source file:richtercloud.reflection.form.builder.jpa.EntityReflectionFormPanel.java

/**
 *
 * @param entityManager//  w  w w . j a  v  a 2s .com
 * @param instance
 * @param entityClass
 * @param fieldMapping
 * @param messageHandler
 * @param editingMode if {@code true} the save button with update an exiting entity and a delete button will be provided, otherwise it will persist a new entity and no delete button will be provided
 * @param fieldRetriever
 * @throws IllegalArgumentException
 * @throws IllegalAccessException
 */
public EntityReflectionFormPanel(EntityManager entityManager, Object instance, Class<?> entityClass,
        Map<Field, JComponent> fieldMapping, MessageHandler messageHandler, boolean editingMode,
        FieldRetriever fieldRetriever, FieldHandler fieldHandler)
        throws IllegalArgumentException, IllegalAccessException {
    super(entityManager, instance, entityClass, fieldMapping, fieldHandler);
    if (messageHandler == null) {
        throw new IllegalArgumentException("messageHandler mustn't be null");
    }
    this.messageHandler = messageHandler;
    if (fieldRetriever == null) {
        throw new IllegalArgumentException("fieldRetriever mustn't be null");
    }
    this.editingMode = editingMode;
    saveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            saveButtonActionPerformed(evt);
        }
    });
    resetButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (EntityReflectionFormPanelUpdateListener updateListener : getUpdateListeners()) {
                updateListener.onReset(new ReflectionFormPanelUpdateEvent(
                        ReflectionFormPanelUpdateEvent.INSTANCE_RESET, null, null));
            }
        }
    });
    horizontalEntityControlsGroup.addGroup(getHorizontalMainGroup());
    verticalEntityControlsGroup.addGroup(getVerticalMainGroup());
    //create button group
    GroupLayout.SequentialGroup buttonGroupHorizontal = getLayout().createSequentialGroup();
    GroupLayout.ParallelGroup buttonGroupVertical = getLayout()
            .createParallelGroup(GroupLayout.Alignment.BASELINE);
    buttonGroupHorizontal.addComponent(saveButton);
    buttonGroupVertical.addComponent(saveButton);
    if (editingMode) {
        deleteButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                deleteButtonActionPerformed(evt);
            }
        });
        buttonGroupHorizontal.addComponent(deleteButton);
        buttonGroupVertical.addComponent(deleteButton);
    }
    resetButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            reset();
        }
    });
    buttonGroupHorizontal.addComponent(resetButton);
    buttonGroupVertical.addComponent(resetButton);
    horizontalEntityControlsGroup.addGroup(buttonGroupHorizontal);
    verticalEntityControlsGroup.addGroup(buttonGroupVertical);
    getLayout().setHorizontalGroup(horizontalEntityControlsGroup);
    getLayout().setVerticalGroup(verticalEntityControlsGroup);
    this.validate();
    this.addContainerListener(new ContainerListener() {
        @Override
        public void componentAdded(ContainerEvent e) {
            if (!(e.getChild() instanceof IdPanel)) {
                return;
            }
            if (idPanel == null) {
                idPanel = (IdPanel) e.getChild();
            } else {
                throw new IllegalArgumentException(
                        "This EntityReflectionFormPanel already contains an IdPanel. Adding a further IdPanel isn't allowed");
            }
        }

        @Override
        public void componentRemoved(ContainerEvent e) {
            if (e.getChild() instanceof IdPanel) {
                idPanel = null;
            }
        }
    });
    this.entityValidator = new EntityValidator(fieldRetriever, messageHandler);
}

From source file:pl.otros.logview.gui.LogViewMainFrame.java

private void addEmptyViewListener() {
    logsTabbedPane.addContainerListener(new ContainerListener() {
        @Override//from ww  w. j av a2s.c om
        public void componentRemoved(ContainerEvent e) {
            setCard();
        }

        @Override
        public void componentAdded(ContainerEvent e) {
            setCard();
        }

        public void setCard() {
            int tabCount = logsTabbedPane.getTabCount();
            if (tabCount > 0) {
                cardLayout.show(cardLayoutPanel, CARD_LAYOUT_LOGS_TABLE);
            } else {
                cardLayout.show(cardLayoutPanel, CARD_LAYOUT_EMPTY);
            }
        }
    });
}

From source file:self.philbrown.javaQuery.$.java

/**
 * Registers common component changes/* w  ww .  j  ava  2  s  .  co m*/
 * @param function receives an instance of javaQuery with the changed view selected, as well as the
 * following arguments:
 * <ol>
 * <li>{@link changeEvent} to define the type of event that was triggered
 * <li>The associated event
 * </ol>
 * @return
 * @see changeEvent
 */
public $ change(final Function function) {
    for (final Component component : views) {
        component.addInputMethodListener(new InputMethodListener() {

            @Override
            public void caretPositionChanged(InputMethodEvent event) {
                function.invoke($.with(component), ChangeEvent.INPUT_CARET_POSITION_CHANGED, event);
            }

            @Override
            public void inputMethodTextChanged(InputMethodEvent event) {
                function.invoke($.with(component), ChangeEvent.INPUT_METHOD_TEXT_CHANGED, event);
            }

        });

        component.addHierarchyBoundsListener(new HierarchyBoundsListener() {

            @Override
            public void ancestorMoved(HierarchyEvent event) {
                function.invoke($.with(component), ChangeEvent.HIERARCHY_ANCESTOR_MOVED, event);
            }

            @Override
            public void ancestorResized(HierarchyEvent event) {
                function.invoke($.with(component), ChangeEvent.HIERARCHY_ANCENSTOR_RESIZED, event);
            }

        });

        component.addHierarchyListener(new HierarchyListener() {

            @Override
            public void hierarchyChanged(HierarchyEvent event) {
                function.invoke($.with(component), ChangeEvent.HIERARCHY_CHANGED, event);
            }

        });

        component.addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                function.invoke($.with(component), ChangeEvent.PROPERTY_CHANGED, event);
            }
        });

        component.addComponentListener(new ComponentListener() {

            @Override
            public void componentHidden(ComponentEvent event) {
                function.invoke($.with(component), ChangeEvent.COMPONENT_HIDDEN, event);
            }

            @Override
            public void componentMoved(ComponentEvent event) {
                function.invoke($.with(component), ChangeEvent.COMPONENT_MOVED, event);
            }

            @Override
            public void componentResized(ComponentEvent event) {
                function.invoke($.with(component), ChangeEvent.COMPONENT_RESIZED, event);
            }

            @Override
            public void componentShown(ComponentEvent event) {
                function.invoke($.with(component), ChangeEvent.COMPONENT_SHOWN, event);
            }

        });

        if (component instanceof Container) {
            ((Container) component).addContainerListener(new ContainerListener() {

                @Override
                public void componentAdded(ContainerEvent event) {
                    function.invoke($.with(component), ChangeEvent.COMPONENT_ADDED, event);
                }

                @Override
                public void componentRemoved(ContainerEvent event) {
                    function.invoke($.with(component), ChangeEvent.COMPONENT_REMOVED, event);
                }

            });
        }
    }
    return this;
}