View Javadoc
1 /*** 2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html 3 */ 4 // stolen from XPath Explorer (http://www.xpathexplorer.com) 5 package net.sourceforge.pmd.cpd; 6 7 import javax.swing.JLabel; 8 import javax.swing.SwingConstants; 9 import java.awt.Component; 10 import java.awt.Container; 11 import java.awt.GridBagConstraints; 12 import java.awt.GridBagLayout; 13 import java.awt.Insets; 14 15 public class GridBagHelper { 16 17 GridBagLayout gridbag; 18 Container container; 19 GridBagConstraints c; 20 int x = 0; 21 int y = 0; 22 int labelAlignment = SwingConstants.RIGHT; 23 double[] weights; 24 25 public GridBagHelper(Container container, double[] weights) { 26 this.container = container; 27 this.weights = weights; 28 29 gridbag = new GridBagLayout(); 30 container.setLayout(gridbag); 31 32 c = new GridBagConstraints(); 33 c.insets = new Insets(2, 2, 2, 2); 34 c.anchor = GridBagConstraints.EAST; 35 c.fill = GridBagConstraints.HORIZONTAL; 36 } 37 38 public void add(Component component) { 39 add(component, 1); 40 } 41 42 public void add(Component component, int width) { 43 c.gridx = x; 44 c.gridy = y; 45 c.weightx = weights[x]; 46 c.gridwidth = width; 47 gridbag.setConstraints(component, c); 48 container.add(component); 49 x += width; 50 } 51 52 public void nextRow() { 53 y++; 54 x = 0; 55 } 56 57 public void addLabel(String label) { 58 add(new JLabel(label, labelAlignment)); 59 } 60 61 } 62

This page was automatically generated by Maven