布局管理器使用代码
2010-08-31 17:40
260 查看
Class
{
super("Teradata DataPump 1.0"); //设置窗口标题
this.setResizable(false); //禁止改变窗口的大小
//实例化一个布局的类
LoginFrameLayout customLayout = new LoginFrameLayout();
getContentPane().setFont(new Font("Helvetica", Font.PLAIN, 12));
getContentPane().setLayout(customLayout); //设置容器
Icon splash=new ImageIcon("image/logo.jpg"); //加入图片、按钮、文本框等
label_1 = new JLabel(splash);
getContentPane().add(label_1);
pack();
setLocationRelativeTo(getOwner()); //将页面显示在屏幕最中间
/*
*
* 添加一个类,用于布局
*/
class LoginFrameLayout implements LayoutManager {
public LoginFrameLayout() {
}
public void addLayoutComponent(String name, Component comp) {
}
public void removeLayoutComponent(Component comp) {
}
public Dimension preferredLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
Insets insets = parent.getInsets();
dim.width = 423 + insets.left + insets.right;
dim.height = 469 + insets.top + insets.bottom;
return dim;
}
public Dimension minimumLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
return dim;
}
public void layoutContainer(Container parent) {
Insets insets = parent.getInsets();
Component c;
c = parent.getComponent(0);
if (c.isVisible()) {c.setBounds(insets.left+16,insets.top+16,392,264);} //picture
c = parent.getComponent(1); //设置空间的位置大小
if (c.isVisible()) {c.setBounds(insets.left+16,insets.top+16,392,264);} //logo
c = parent.getComponent(2);
if (c.isVisible()) {c.setBounds(insets.left+120,insets.top+400,88,32);} //button logout
c = parent.getComponent(3);
}
}
}
相关文章推荐
- 使用SvcUtil.exe生成客户端代码和配置、WCF Test Client调试WCF
- 在网页加代码强制IE8使用兼容性视图解决网页显示不正确的办法
- 使用lint工具优化Android代码
- Doxygen for C++使用说明——注释代码一
- OC ARC之基本使用(代码分析)
- Android 代码中AddView 使用anko
- ibatis - 自动代码生成工具abator 使用介绍(s00n原作)
- 使用 Lombok 减少你的样板代码
- 在一个项目中同时使用Swift和Objective-C代码混合编程的方法
- Keras使用tensorflow代码
- jar包修改并重新打包,jar包反编译使用工具以及修改代码方法
- Android Studio使用技巧之快速定位代码文件所在的电脑磁盘文件夹位置
- Android无序广播最近使用整理——基础代码、权限
- Android三句代码使用沉浸式状态栏
- 使用webstrom开发react-native时react-native代码会出现红色下划线的解决方法
- android在程序代码中使用res目录下的String资源
- WebView使用中js调用java代码时targetSdkVersion大于17时,无法调用成功
- Android日志:代码混淆,使用说明
- 使用gitbash进行代码上传等命令知识点。