0

I want to place a Button in the center of a row of a Container , the Button is the only component of the Container. How to achieve that ?

bharath
  • 14,283
  • 16
  • 57
  • 95

2 Answers2

0
Container c = new Container(new FlowLayout(Component.CENTER)); 
Button b = new Button(); 
c.addComponent(b); 
Shai Almog
  • 51,749
  • 5
  • 35
  • 65
0

Just set the BorderLayout to Container. Then add the Button into Container and set the constraints to CENTER.

For example,

Container c = new Container(new BorderLayout());
Button btn = new Button("Sample");
c.addComponent(BorderLayout.CENTER, btn);
bharath
  • 14,283
  • 16
  • 57
  • 95