1 package net.matuschek.swing; 2 3 import java.awt.*; 4 import javax.swing.*; 5 8 9 10 21 public class OptionPanel extends JPanel { 22 23 private static final long serialVersionUID = -4539847595846318366L; 24 25 private int count=0; 26 private int inset=2; 27 28 32 public OptionPanel(int inset) { 33 super(); 34 setLayout(new GridBagLayout()); 35 this.inset = inset; 36 } 37 38 48 public void add(String labelText, JComponent comp, int fill) { 49 JLabel label = new JLabel(); 50 label.setText(labelText); 51 GridBagConstraints consLeft = new GridBagConstraints(); 52 consLeft.gridx = 0; 53 consLeft.gridy = count; 54 consLeft.insets = new Insets(inset,inset,inset,inset); 55 consLeft.anchor = GridBagConstraints.WEST; 56 this.add(label, consLeft); 57 58 GridBagConstraints consRight = new GridBagConstraints(); 59 consRight.gridx = 1; 60 consRight.gridy = count; 61 consRight.insets = new Insets(inset,inset,inset,inset); 62 consRight.fill = fill; 63 consRight.anchor = GridBagConstraints.WEST; 64 65 this.add(comp, consRight); 66 67 count++; 68 } 69 70 78 public void add(String labelText, JComponent comp) { 79 add(labelText,comp,GridBagConstraints.NONE); 80 } 81 82 83 } | Popular Tags |