Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Rainhard Fischer   on Oct 09 In Java Category.

  
Question Answered By: Bellona Lopez   on Oct 09

import javax.swing.*;
import java.awt.*;


public class  ContainersButton extends JPanel
{
public static  void main(String []args)
{
ContainersButton containersButton = new ContainersButton();
JFrame frame  = new JFrame("ShowContainedButtons");

frame.setTitle("Show contained  buttons in frame");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 400);
frame.getContentPane().add(containersButton,
BorderLayout.CENTER);
frame.setVisible(true);
}



public ContainersButton()
{
this.setBackground(Color.white);
this.setFont(new Font("Dialog", Font.BOLD, 24));

JPanel p1 = new JPanel();
p1.setBackground(new Color(200, 200, 200));
this.add(p1);
p1.add(new JButton("#1"));

JPanel p2 = new JPanel();
p2.setBackground(new Color(150, 150, 150));
p1.add(p2);
p2.add(new JButton("#2"));

JPanel p3 = new JPanel();
p3.setBackground(new Color(100, 100, 100));
p2.add(p3);
p3.add(new JButton("#3"));

JPanel p4 = new JPanel();
p4.setBackground(new Color(150, 150, 150));
p1.add(p4);
p4.add(new JButton("#4"));
p4.add(new JButton("#5"));

this.add(new JButton("#6"));


}
}

Share: 

 
 
Didn't find what you were looking for? Find more on ContainedButtons Or get search suggestion and latest updates.


Tagged: