Java JPanel(boolean isDoubleBuffered) Constructor

Syntax

JPanel(boolean isDoubleBuffered) constructor from JPanel has the following syntax.

public JPanel(boolean isDoubleBuffered)

Example

In the following code shows how to use JPanel.JPanel(boolean isDoubleBuffered) constructor.


//www  .ja  va 2  s .  co  m
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main {

  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);
      }
      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);
  }

}