1 package net.matuschek.swing; 2 3 import java.awt.*; 4 import javax.swing.*; 5 8 9 10 18 public class VerticalAlignPanel extends JPanel { 19 20 private static final long serialVersionUID = -5964950356897442955L; 21 22 private int count=0; 23 private int inset=2; 24 25 28 public VerticalAlignPanel() { 29 super(); 30 setLayout(new GridBagLayout()); 31 } 32 33 37 public VerticalAlignPanel(int inset) { 38 this(); 39 this.inset = inset; 40 } 41 42 50 public void add(JComponent comp, int fill) { 51 GridBagConstraints consRight = new GridBagConstraints(); 52 consRight.gridx = 0; 53 consRight.gridy = count; 54 consRight.insets = new Insets(inset,inset,inset,inset); 55 consRight.fill = fill; 56 consRight.anchor = GridBagConstraints.CENTER; 57 58 this.add(comp, consRight); 59 60 count++; 61 } 62 63 69 public void add(JComponent comp) { 70 add(comp,GridBagConstraints.NONE); 71 } 72 73 74 } | Popular Tags |