📄 verticalalignpanel.java
字号:
package net.matuschek.swing;
import java.awt.*;
import javax.swing.*;
/*********************************************
Copyright (c) 2001 by Daniel Matuschek
*********************************************/
/**
* This is a JPanel object that allows "stacking" of components without
* explicit use of the GridBagLayout. Simply create that panel and add
* components to it.
*
* @author Daniel Matuschek
* @version $Revision: 1.4 $
*/
public class VerticalAlignPanel extends JPanel {
private static final long serialVersionUID = -5964950356897442955L;
private int count=0;
private int inset=2;
/**
* Initializes a new VerticalAlignPanel object.
*/
public VerticalAlignPanel() {
super();
setLayout(new GridBagLayout());
}
/**
* Initializes a new VerticalAlignPanel object and sets the inset value.
* The inset is used to have some space around the components
*/
public VerticalAlignPanel(int inset) {
this();
this.inset = inset;
}
/**
* adds a new line to the VerticalAlignPanel
* with the given Component
* @param comp a JComponent object that should be added in the next line
* @param fill can be java.awt.GridBagConstraints.
* NONE|HORIZONTAL|VERTICAL|BOTH and describes if the component should
* fill the place at the right side or keep its defaults size
*/
public void add(JComponent comp, int fill) {
GridBagConstraints consRight = new GridBagConstraints();
consRight.gridx = 0;
consRight.gridy = count;
consRight.insets = new Insets(inset,inset,inset,inset);
consRight.fill = fill;
consRight.anchor = GridBagConstraints.CENTER;
this.add(comp, consRight);
count++;
}
/**
* adds a new line to the VerticalAlignPanel
* with the given Component
* @param comp a JComponent object that should be added in the next line
* @see #add(JComponent, int) (fill will be set to NONE)
*/
public void add(JComponent comp) {
add(comp,GridBagConstraints.NONE);
}
} // VerticalAlignPanel
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -