java Swing 工具

GUIUtils工具类详解
本文介绍了一个名为GUIUtils的工具类,该类提供了一系列用于简化GUI操作的静态方法,包括居中窗口、最大化JFrame及锁定JTable列宽等功能。这些方法能够帮助开发者更便捷地进行GUI开发。

/*
* GUIUtils.java
*
* Copyright (c) 2004-2008 Gregory Kotsaftis
* gregkotsaftis@yahoo.com
* http://zeus-jscl.sourceforge.net/
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package gr.zeus.util;

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.Window;
import javax.swing.JFrame;
import javax.swing.table.TableColumn;

/**
* GUI Helper class, contains static methods that are used all the time.
* <p>
* @author Gregory Kotsaftis
* @since 1.0
*/
public final class GUIUtils {

/**
* Centers a window on screen.
* <p>
* @param w The window to center.
*/
public static void centerOnScreen(Window w)
{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension splashSize = w.getPreferredSize();
w.setLocation(screenSize.width / 2 - (splashSize.width / 2),
screenSize.height / 2 - (splashSize.height / 2));
}


/**
* Maximizes a JFrame, just like the 'maximize window' button does.
* <p>
* @param f The frame to maximize.
*/
public static void maximizeJFrame(JFrame f)
{
f.setExtendedState( Frame.MAXIMIZED_BOTH );
}


/**
* Locks a Jtable's column width with 'pixels' size.
* <p>
* @param tc The table column.
* @param pixels The desired pixels.
*/
public static void lockJTableColumnWidth(TableColumn tc, int pixels)
{
if( tc!=null )
{
tc.setMinWidth( pixels );
tc.setMaxWidth( pixels );
tc.setPreferredWidth( pixels );
tc.setResizable( false );
}
}


/**
* Hides a specific column of a JTable.
* <p>
* @param tc The table column.
*/
public static void hideJTableColumn(TableColumn tc)
{
lockJTableColumnWidth(tc, 0);
}

}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值