java中的布局管理

来源:百度知道 编辑:UC知道 时间:2024/09/22 21:31:29
容器如果被设定了大小,放入容器中的组件不随容器大小的变化而改变,应该使用哪一种布局啊?

XYLayout应该是可以实现的。用这种布局还可以指定放入容器组件的具体位置,不过是绝对位置。

setLayout(null);
setBounds(100,100,200,200);

你可以用XYLayout实现

不解

给你一个XYLayout代码。

import java.awt.*;
import java.io.Serializable;
import java.util.Hashtable;

public class XYLayout implements LayoutManager2, Serializable {
public XYLayout() {
info = new Hashtable();
}

public XYLayout(int width, int height) {
info = new Hashtable();
this.width = width;
this.height = height;
}

public int getWidth() {
return width;
}

public void setWidth(int width) {
this.width = width;
}

public int getHeight() {
return height;
}

public void setHeight(int height) {
this.height = height;
}

public String toString() {
return "XYLayo