How to Resize the container with many component? and the component will vary according with the size of container?

lxianfeng 2001-06-22 01:52:00
...全文
70 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
knight_qmh 2001-06-22
  • 打赏
  • 举报
回复
public class Example extends Frame implements LayoutManager {
Dimension origin = new Dimension(0, 0);

public void init()
{
Button showButton = new Button("Show");
Button fetchButton = new Button("Fetch");
Button queryButton = new Button("Query");
add(showButton);
add(fetchButton);
add(queryButton);
}

public Dimension preferredLayoutSize(Container c){return origin;}
public Dimension minimumLayoutSize(Container c){return origin;}
public void addLayoutComponent(String s, Component c) {}
public void removeLayoutComponent(Component c) {}
public void layoutContainer(Container c) {
Rectangle b = c.getBounds();
int topHeight = 90;
int inset = 4;
showButton.setBounds(b.width-2*inset-120, inset, 120, 25);
fetchButton.setBounds(b.width-2*inset-120, 60, 120, 25);
query.setBounds(inset, inset, b.width-2*inset - 150, 80);
}

}

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧