List of usage examples for javax.swing JPanel addContainerListener
public synchronized void addContainerListener(ContainerListener l)
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 w w. j av 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: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); }/*from w w w.j av a 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); }//www .j av 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); }