FileDocCategorySizeDatePackage
OpaqueExample.javaAPI DocExample1237Mon Nov 09 12:45:54 GMT 1998None

OpaqueExample

public class OpaqueExample extends Object

Fields Summary
Constructors Summary
Methods Summary
public static javax.swing.JPanelcreateNested(boolean opaque)

    JPanel outer = new JPanel(new FlowLayout());
    JPanel inner = new JPanel(new FlowLayout());
    outer.setBackground(Color.white);
    inner.setBackground(Color.black);

    inner.setOpaque(opaque);
    inner.setBorder(BorderFactory.createLineBorder(Color.gray));

    inner.add(new JButton("Button"));
    outer.add(inner);

    return outer;
  
public static voidmain(java.lang.String[] args)


    // Create 2 JPanels (opaque), one containing another opaque JPanel, and
    // the other containing a nonopaque JPanel
    JPanel opaque = createNested(true);
    JPanel notOpaque = createNested(false);

    // Throw it all together in a JFrame
    JFrame f = new JFrame();
    f.addWindowListener(new BasicWindowMonitor());
    f.getContentPane().setLayout(new FlowLayout());
    f.getContentPane().add(opaque);
    f.getContentPane().add(notOpaque);
    f.pack();
    f.setVisible(true);