aspose file tools*
The moose likes Applets and the fly likes Layout Problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Layout Problems" Watch "Layout Problems" New topic
Author

Layout Problems

Sam
Greenhorn

Joined: Jun 23, 2000
Posts: 26
Hi Friends,
I'm facing a layout problem and I have to make the applet ready and give it to my boss urgently. So help me out !!! Following is the code. I have created three panels(all with GridLayout) and my applet also have GridLayout. I have added the panels on the applet and they are ok. The problem is with two buttons. I wanna add them below the three panels, in the center. Thats the problem and I'm not able to solve it since I'm not very proficient with layout managers. Help me out!!
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Rest extends Applet {
Checkbox c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12;
Panel p1,p2,p3,p4;
Label l1,l2,l3;
Button b1,b2;
Label l4,l5,l6;
public void init()
{
setLayout(new GridLayout(1,3));
l1=new Label("PIZZAS");
l2=new Label("FAST FOOD");
l3=new Label("BURGERS");
l4=new Label("");
l5=new Label("");
l6=new Label("");
b1=new Button("SUBMIT");
b2=new Button("CANCEL");
c1=new Checkbox("1");
c2=new Checkbox("2");
c3=new Checkbox("3");
c4=new Checkbox("4");
c5=new Checkbox();
c6=new Checkbox();
c7=new Checkbox();
c8=new Checkbox();
c9=new Checkbox();
c10=new Checkbox();
c11=new Checkbox();
c12=new Checkbox();
p1=new Panel();
p2=new Panel();
p3=new Panel();
p4=new Panel();
pp=new Panel();
p1.setLayout(new GridLayout(5,0));
p1.add(l1);
p1.add(c1);
p1.add(c2);
p1.add(c3);
p1.add(c4);
p2.setLayout(new GridLayout(5,0));
p2.add(l2);
p2.add(c5);
p2.add(c6);
p2.add(c7);
p2.add(c8);
p3.setLayout(new GridLayout(5,0));
p3.add(l3);
p3.add(c9);
p3.add(c10);
p3.add(c11);
p3.add(c12);
p4.setLayout(new GridLayout(1,5));
p4.add(l4);
p4.add(l5);
p4.add(b1);
p4.add(l6);
p4.add(b2);
add(p1);
add(p2);
add(p3);
setLayout(new FlowLayout());
add(p4);
}
}
Thanks in advance
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
Try this

There's not a lot different. I just added another panel and used GridLayout for the applet itself. You'll notice that is seems more 'centered' at different sizes. This is a result of using the flowlayout in the button's panel. You can resolve this by figuring out the size that looks good and then adding this,
this.setSize( bestWidth, bestHeight );
this.setResizable( false );
If you call this applet from an html page the size parameters in the html will override these, so make sure the html params are the same. You might have been able to make this more accurately using the GridBagLayout but, personally, I would simply set the layout to null in the applet, add the panel containing the checkboxes and then set the bounds of the button panel using x and y variables that are calculated proportionally to the checkbox panel. Also, I would have the button panel adjust dynamically in the repaint method. This way they will get repositioned when the applet is resized. I hope this helps.
Sean
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Layout Problems