Where can I get the XYLayout source code ?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Zhou_Yonghua
Posted On:   Friday, April 19, 2002 01:49 AM

When I put the components on the container, I find it is
very diffult to put them on the location as I need.
Even the method setLocation can not help me .So I want to
use XYLayout.
Thanks.

Re: Where can I get the XYLayout source code ?

Posted By:   Lynn_Hollerman  
Posted On:   Friday, April 19, 2002 06:39 AM

Do you mean this code?

---

import java.awt.*;

public class XYLayout implements LayoutManager {
public void addLayoutComponent(String name,Component component) {}
public void removeLayoutComponent(Component component) {}
public Dimension minimumLayoutSize(Container container) {
int height = 0;
int width = 0;
int count = container.getComponentCount();
for(int i=0; i Component component = container.getComponent(i);
Dimension dim = component.getPreferredSize();
Point pt = component.getLocation();
if(width < (pt.x + dim.width))
width = pt.x + dim.width;
if(height < (pt.y + dim.height))
height = pt.y + dim.height;
}
return(new Dimension(width,height));
}
public Dimension preferredLayoutSize(Container container) {
return minimumLayoutSize(container);
}
public void layoutContainer(Container container) {
int count = container.getComponentCount();
for(int i=0; i Component component = container.getComponent(i);
Dimension dim = component.getPreferredSize();
component.setSize(dim.width,dim.height);
}
}
}



Lynn.
About | Sitemap | Contact