下面列出了java.awt.GridBagConstraints#clone ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void addLabeledComponentToGBL( String name,
JComponent c,
GridBagLayout gbl,
GridBagConstraints gbc,
Container target ) {
LabelV2 l = new LabelV2( name );
GridBagConstraints gbcLabel = (GridBagConstraints) gbc.clone();
gbcLabel.insets = new Insets( 2, 2, 2, 0 );
gbcLabel.gridwidth = 1;
gbcLabel.weightx = 0;
if ( c == null )
c = new JLabel( "" );
gbl.setConstraints( l, gbcLabel );
target.add( l );
gbl.setConstraints( c, gbc );
target.add( c );
}
private void addLabeledComponentToGBL( String name,
JComponent c,
GridBagLayout gbl,
GridBagConstraints gbc,
Container target ) {
LabelV2 l = new LabelV2( name );
GridBagConstraints gbcLabel = (GridBagConstraints) gbc.clone();
gbcLabel.insets = new Insets( 2, 2, 2, 0 );
gbcLabel.gridwidth = 1;
gbcLabel.weightx = 0;
if ( c == null )
c = new JLabel( "" );
gbl.setConstraints( l, gbcLabel );
target.add( l );
gbl.setConstraints( c, gbc );
target.add( c );
}
private void addLabeledComponentToGBL( String name,
JComponent c,
GridBagLayout gbl,
GridBagConstraints gbc,
Container target ) {
LabelV2 l = new LabelV2( name );
GridBagConstraints gbcLabel = (GridBagConstraints) gbc.clone();
gbcLabel.insets = new Insets( 2, 2, 2, 0 );
gbcLabel.gridwidth = 1;
gbcLabel.weightx = 0;
if ( c == null )
c = new JLabel( "" );
gbl.setConstraints( l, gbcLabel );
target.add( l );
gbl.setConstraints( c, gbc );
target.add( c );
}
private void addLabeledComponentToGBL( String name,
JComponent c,
GridBagLayout gbl,
GridBagConstraints gbc,
Container target ) {
LabelV2 l = new LabelV2( name );
GridBagConstraints gbcLabel = (GridBagConstraints) gbc.clone();
gbcLabel.insets = new Insets( 2, 2, 2, 0 );
gbcLabel.gridwidth = 1;
gbcLabel.weightx = 0;
if ( c == null )
c = new JLabel( "" );
gbl.setConstraints( l, gbcLabel );
target.add( l );
gbl.setConstraints( c, gbc );
target.add( c );
}
private void addLabeledComponentToGBL( String name,
JComponent c,
GridBagLayout gbl,
GridBagConstraints gbc,
Container target ) {
LabelV2 l = new LabelV2( name );
GridBagConstraints gbcLabel = (GridBagConstraints) gbc.clone();
gbcLabel.insets = new Insets( 2, 2, 2, 0 );
gbcLabel.gridwidth = 1;
gbcLabel.weightx = 0;
if ( c == null )
c = new JLabel( "" );
gbl.setConstraints( l, gbcLabel );
target.add( l );
gbl.setConstraints( c, gbc );
target.add( c );
}
private void addLabeledComponentToGBL( String name,
JComponent c,
GridBagLayout gbl,
GridBagConstraints gbc,
Container target ) {
LabelV2 l = new LabelV2( name );
GridBagConstraints gbcLabel = (GridBagConstraints) gbc.clone();
gbcLabel.insets = new Insets( 2, 2, 2, 0 );
gbcLabel.gridwidth = 1;
gbcLabel.weightx = 0;
if ( c == null )
c = new JLabel( "" );
gbl.setConstraints( l, gbcLabel );
target.add( l );
gbl.setConstraints( c, gbc );
target.add( c );
}
private void addLabeledComponentToGBL( String name,
JComponent c,
GridBagLayout gbl,
GridBagConstraints gbc,
Container target ) {
LabelV2 l = new LabelV2( name );
GridBagConstraints gbcLabel = (GridBagConstraints) gbc.clone();
gbcLabel.insets = new Insets( 2, 2, 2, 0 );
gbcLabel.gridwidth = 1;
gbcLabel.weightx = 0;
if ( c == null )
c = new JLabel( "" );
gbl.setConstraints( l, gbcLabel );
target.add( l );
gbl.setConstraints( c, gbc );
target.add( c );
}
private void addLabeledComponentToGBL( String name,
JComponent c,
GridBagLayout gbl,
GridBagConstraints gbc,
Container target ) {
LabelV2 l = new LabelV2( name );
GridBagConstraints gbcLabel = (GridBagConstraints) gbc.clone();
gbcLabel.insets = new Insets( 2, 2, 2, 0 );
gbcLabel.gridwidth = 1;
gbcLabel.weightx = 0;
if ( c == null )
c = new JLabel( "" );
gbl.setConstraints( l, gbcLabel );
target.add( l );
gbl.setConstraints( c, gbc );
target.add( c );
}
private void addLabeledComponentToGBL( String name,
JComponent c,
GridBagLayout gbl,
GridBagConstraints gbc,
Container target ) {
LabelV2 l = new LabelV2( name );
GridBagConstraints gbcLabel = (GridBagConstraints) gbc.clone();
gbcLabel.insets = new Insets( 2, 2, 2, 0 );
gbcLabel.gridwidth = 1;
gbcLabel.weightx = 0;
if ( c == null )
c = new JLabel( "" );
gbl.setConstraints( l, gbcLabel );
target.add( l );
gbl.setConstraints( c, gbc );
target.add( c );
}
private void addLabeledComponentToGBL( String name,
JComponent c,
GridBagLayout gbl,
GridBagConstraints gbc,
Container target ) {
LabelV2 l = new LabelV2( name );
GridBagConstraints gbcLabel = (GridBagConstraints) gbc.clone();
gbcLabel.insets = new Insets( 2, 2, 2, 0 );
gbcLabel.gridwidth = 1;
gbcLabel.weightx = 0;
if ( c == null )
c = new JLabel( "" );
gbl.setConstraints( l, gbcLabel );
target.add( l );
gbl.setConstraints( c, gbc );
target.add( c );
}
private void addLabeledComponentToGBL( String name,
JComponent c,
GridBagLayout gbl,
GridBagConstraints gbc,
Container target ) {
LabelV2 l = new LabelV2( name );
GridBagConstraints gbcLabel = (GridBagConstraints) gbc.clone();
gbcLabel.insets = new Insets( 2, 2, 2, 0 );
gbcLabel.gridwidth = 1;
gbcLabel.weightx = 0;
if ( c == null )
c = new JLabel( "" );
gbl.setConstraints( l, gbcLabel );
target.add( l );
gbl.setConstraints( c, gbc );
target.add( c );
}
private void addLabeledComponentToGBL( String name,
JComponent c,
GridBagLayout gbl,
GridBagConstraints gbc,
Container target ) {
LabelV2 l = new LabelV2( name );
GridBagConstraints gbcLabel = (GridBagConstraints) gbc.clone();
gbcLabel.insets = new Insets( 2, 2, 2, 0 );
gbcLabel.gridwidth = 1;
gbcLabel.weightx = 0;
if ( c == null )
c = new JLabel( "" );
gbl.setConstraints( l, gbcLabel );
target.add( l );
gbl.setConstraints( c, gbc );
target.add( c );
}
private void addLabeledComponentToGBL( String name,
JComponent c,
GridBagLayout gbl,
GridBagConstraints gbc,
Container target ) {
LabelV2 l = new LabelV2( name );
GridBagConstraints gbcLabel = (GridBagConstraints) gbc.clone();
gbcLabel.insets = new Insets( 2, 2, 2, 0 );
gbcLabel.gridwidth = 1;
gbcLabel.weightx = 0;
if ( c == null )
c = new JLabel( "" );
gbl.setConstraints( l, gbcLabel );
target.add( l );
gbl.setConstraints( c, gbc );
target.add( c );
}
private void init() {
labelConstraints = new GridBagConstraints();
labelConstraints.gridx = 0;
labelConstraints.gridy = 0;
labelConstraints.weightx = 0.0;
labelConstraints.weighty = 0.0;
labelConstraints.fill = GridBagConstraints.NONE;
labelConstraints.anchor = GridBagConstraints.EAST;
fieldConstraints = new GridBagConstraints();
fieldConstraints.gridx = 1;
fieldConstraints.gridy = 0;
fieldConstraints.weightx = 1.0;
fieldConstraints.weighty = 0.0;
fieldConstraints.fill = GridBagConstraints.HORIZONTAL;
wideLabelConstraints = new GridBagConstraints();
wideLabelConstraints.gridx = 0;
wideLabelConstraints.gridy = 0;
wideLabelConstraints.gridwidth = 2;
wideLabelConstraints.weightx = 1.0;
wideLabelConstraints.weighty = 0.0;
wideLabelConstraints.fill = GridBagConstraints.HORIZONTAL;
wideFieldConstraints = new GridBagConstraints();
wideFieldConstraints.gridx = 0;
wideFieldConstraints.gridy = 0;
wideFieldConstraints.gridwidth = 2;
wideFieldConstraints.weightx = 1.0;
wideFieldConstraints.weighty = 1.0;
wideFieldConstraints.fill = GridBagConstraints.BOTH;
componentConstraints = (GridBagConstraints) wideFieldConstraints.clone();
GridBagConstraints buttonConstraints = (GridBagConstraints) wideLabelConstraints.clone();
buttonConstraints.gridy = 1000;
panel.add(buttons, buttonConstraints);
}
public static JPanel makeGrid(int cols, GridBagConstraints template, Container... containers) {
JPanel ans = new JPanel(new GridBagLayout());
int i = -1;
for (Container container : containers) {
for (Component comp : container.getComponents()) {
i++;
GridBagConstraints c = (GridBagConstraints) template.clone();
c.gridx = i % cols;
c.gridy = i / cols;
ans.add(comp, c);
}
}
return ans;
}
public Builder(GridBagConstraints gbc) {
this.gbc = (GridBagConstraints) gbc.clone();
}