⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swingutils.java

📁 这是一款应用程序与数据库联接
💻 JAVA
字号:
/* ===========================================================
 * JDBMonitor : a flexiable JDBC Monitor for the Java(tm) platform
 * ===========================================================
 *
 * (C) Copyright 2006-2006, by yang zhongke
 *
 * Project Info:  http://www.cownew.com
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
 * USA.  
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 * in the United States and other countries.]
 *
 * ---------------
 * SwingUtils.java
 * ---------------
 * (C) Copyright 2006-2006, by yang zhongke
 *
 * Original Author:  yang zhongke;
 *
 * Changes
 * -------
 *
 */
package com.cownew.JDBMonitor.listenerImpl.uicommon;

import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.UIManager.LookAndFeelInfo;

import com.cownew.JDBMonitor.common.CommonUtils;

public class SwingUtils
{
	/**
	 * make Container frame in the center of the owner
	 * @param owner
	 * @param frame
	 */
	public static void centerInParent(Container owner,Container frame)
	{
		Rectangle parentRect = owner.getBounds();
		Point pos = new Point();
		pos.setLocation(parentRect.x+parentRect.width/4,parentRect.y+parentRect.height/4);
		frame.setLocation(pos);
	}
	
	/**
	 * init the JFrame size
	 * @param frame
	 */
	public static void initWindowSize(JFrame frame)
	{
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		frame.setBounds((int)dim.getWidth()/4,(int)dim.getHeight()/4,
				(int)dim.getWidth()/2,(int)dim.getHeight()/2);
	}
	
	/**
	 * int the submenu of the LookAndFeel Menu(menuItemSkin)
	 * @param owner
	 * @param menuItemSkin 
	 */
	public static void initLookAndFeelMenu(final Component owner,JMenu menuItemSkin)
	{		
		LookAndFeelInfo[] skins = UIManager.getInstalledLookAndFeels();
		ButtonGroup btnGroupSkins = new ButtonGroup();
		for(int i=0,n=skins.length;i<n;i++)
		{
			final LookAndFeelInfo skinInfo = skins[i];
			JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(skinInfo.getName());
			if(i==0)
			{
				menuItem.setSelected(true);
			}		
			btnGroupSkins.add(menuItem);
			menuItem.addActionListener(new ActionListener(){

				public void actionPerformed(ActionEvent e)
				{
					try
					{
						UIManager.setLookAndFeel(skinInfo.getClassName());
						SwingUtilities.updateComponentTreeUI(owner);
					} catch (ClassNotFoundException e1)
					{
						throw CommonUtils.toRuntimeException(e1);
					} catch (InstantiationException e1)
					{
						throw CommonUtils.toRuntimeException(e1);
					} catch (IllegalAccessException e1)
					{
						throw CommonUtils.toRuntimeException(e1);
					} catch (UnsupportedLookAndFeelException e1)
					{
						throw CommonUtils.toRuntimeException(e1);
					}					
				}
				
			});
			menuItemSkin.add(menuItem);
		}				
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -