📄 swingutil.java
字号:
/*
* SwingUtil.java
*
* Copyright (C) 2000 Jason M. Hanley
* Released under the GNU General Public License (GPL)
* See license.txt for additional information.
*
* Created on July 27, 2000, 1:10 AM
*/
package fate.ui;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* General Swing utility class.
*
* @author preylude@s3m.com
* @version 0.1.0
*/
public class SwingUtil extends Object {
/** Creates new SwingUtil */
public SwingUtil() {
}
public static void centerWindow( java.awt.Window win )
{
Dimension winSize = win.getSize();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int newX, newY;
newX = (screenSize.width / 2) - (winSize.width / 2);
newY = (screenSize.height / 2) - (winSize.height / 2);
win.setLocation( newX, newY );
}
/** Creates a new button, adds it to component and returns it */
public static JButton addButton( Container component, String title,
char hotKey, String actionCommand, ActionListener listener ) {
JButton button = new JButton( title );
button.setMnemonic( hotKey );
button.setActionCommand( actionCommand );
button.addActionListener( listener );
button.setAlignmentX( Component.CENTER_ALIGNMENT );
button.setOpaque( false );
component.add( button );
return button;
}
/** Creates a new text field, adds it to component and returns it */
public static JTextField addTextField( Container component, String title, int length ) {
JTextField textField = new JTextField( length );
return addField( component, title, textField );
}
/** Creates a new text field, adds it to component and returns it */
public static JPasswordField addPasswordField( Container component, String title, int length ) {
JPasswordField textField = new JPasswordField( length );
return (JPasswordField)addField( component, title, textField );
}
/** Creates a new text field, adds it to component and returns it */
public static JTextField addField( Container component, String title, JTextField textField ) {
JPanel panel = new JPanel();
panel.setOpaque( false );
JLabel label = new JLabel( title + ":" );
label.setOpaque( false );
label.setForeground( Color.black );
panel.add( label );
panel.add( Box.createHorizontalGlue() );
// label.setAlignmentX( Component.LEFT_ALIGNMENT );
panel.add( textField );
// textField.setAlignmentX( Component.RIGHT_ALIGNMENT );
// panel.setAlignmentX( Component.LEFT_ALIGNMENT );
component.add( panel );
return textField;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -