📄 swingutil.java
字号:
package org.theblueplanet.util;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.Toolkit;
import java.awt.Window;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
* Utility methods for Swing components.
*
* @author Charles M間nin
* @since September 28, 2001
* @version 1.0
*/
public class SwingUtil {
/**
* Centers a window on the screen
*
* @param window The JWindow object to center
*/
public static void center(Window window) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension windowSize = window.getSize();
window.setLocation((screenSize.width - windowSize.width) / 2, (screenSize.height - windowSize.height) / 2);
}
/**
* Helper method to add a Component to a Container with a GridBagLayout
*
* @param container The Container
* @param component The Component to ad to the Container
* @param gbc The GridBagConstraints Object
* @param x The x position of the Component
* @param y The y position of the Component
* @param width The width of the Component
* @param height The height of the Component
*/
public static void addUsingGBL(Container container, Component component,
GridBagConstraints gbc, int x, int y,
int width, int height) {
gbc.gridx = x;
gbc.gridy = y;
gbc.gridwidth = width;
gbc.gridheight = height;
container.add(component, gbc);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -