List of usage examples for java.awt GridBagConstraints GridBagConstraints
public GridBagConstraints()
From source file:Main.java
public static GridBagConstraints createConstraints(int gridx, int gridy, int gridwidth, int gridheight, int anchor, int fill, Insets insets) { GridBagConstraints c = new GridBagConstraints(); c.gridx = gridx;/*from ww w . j a va 2 s . c o m*/ c.gridy = gridy; c.gridwidth = gridwidth; c.gridheight = gridheight; c.weightx = 0.5; c.weighty = 0.5; c.anchor = anchor; c.fill = fill; c.insets = insets; return c; }
From source file:Main.java
public static JPanel createVertical(final Component... components) { final JPanel jp = new JPanel(new GridBagLayout()); final GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0;// ww w . j a va 2 s .co m gbc.gridy = 0; gbc.insets = new Insets(0, 5, 4, 5); gbc.anchor = GridBagConstraints.NORTH; gbc.weightx = 1.0; gbc.fill = GridBagConstraints.HORIZONTAL; for (final Component component : components) { if (gbc.gridy == components.length - 1) { gbc.weighty = 1.0; } jp.add(component, gbc); gbc.gridy++; } return jp; }
From source file:Main.java
/** * Custom creation method for {@link GridBagConstraints}. *//*from w w w . j ava 2 s. com*/ public static GridBagConstraints createCustomGBC(final int x, final int y) { final GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = x; gbc.gridy = y; return gbc; }
From source file:Main.java
public static GridBagConstraints compConstraint(int gridx, int gridy, int fill, int anchor) { GridBagConstraints constraints = new GridBagConstraints(); constraints.gridx = gridx;// w w w . ja v a 2s . c om constraints.gridy = gridy; constraints.fill = fill; constraints.anchor = anchor; return constraints; }
From source file:Main.java
static void addComponent(final Container cont, final GridBagLayout gbl, final Component c, final int x, final int y, final int width, final int height, final double weightx, final double weighty, int fill) { final GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = fill;//GridBagConstraints.BOTH; gbc.gridx = x;// www. j a v a 2 s . c om gbc.gridy = y; gbc.gridwidth = width; gbc.gridheight = height; gbc.weightx = weightx; gbc.weighty = weighty; gbl.setConstraints(c, gbc); cont.add(c); }
From source file:Main.java
/** * Helper method that taked a component and adds it to a container using * {@link java.awt.GridBagConstraints}./*from ww w .ja va 2 s. c om*/ * @param container The container to add to. * @param component The componend to be added. * @param gridx GridBagConstraints value. * @param gridy GridBagConstraints value. * @param fill GridBagConstraints value. */ public static void addWithLesserGridBagConstraints(final Container container, final Component component, final int gridx, final int gridy, final int fill) { GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = gridx; gridBagConstraints.gridy = gridy; gridBagConstraints.fill = fill; container.add(component, gridBagConstraints); }
From source file:Main.java
/** * Helper method that taked a component and adds it to a container using * {@link java.awt.GridBagConstraints}./*from w ww . j a va2s . c o m*/ * @param container The container to add to. * @param component The componend to be added. * @param gridx GridBagConstraints value. * @param gridy GridBagConstraints value. * @param weightx GridBagConstraints value. * @param weighty GridBagConstraints value. * @param fill GridBagConstraints value. * @param insets GridBagConstraints value. */ public static void addWithGridBagConstraints(final Container container, final Component component, final int gridx, final int gridy, final double weightx, final double weighty, final int fill, final Insets insets) { GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = gridx; gridBagConstraints.gridy = gridy; gridBagConstraints.weightx = weightx; gridBagConstraints.weighty = weighty; gridBagConstraints.fill = fill; gridBagConstraints.insets = insets; container.add(component, gridBagConstraints); }
From source file:Main.java
/** * Lays out a list of controls in a compact grid-layout, meaning that each * cell in the grid only takes up it's preferred size. * /* w w w . j a v a 2 s .c om*/ * @param parent the parent <code>Container</code> * @param colCount the number of columns * @param padding the number of pixels to pad between cells * @param components a <code>List</code> of <code>Component</code>s that * should be added to <code>parent</code> */ public static void makeCompactGrid(Container parent, int colCount, int padding, List<? extends Component> components) { parent.setLayout(new GridBagLayout()); final int componentCount = components.size(); final int rowCount = getRowCount(componentCount, colCount); final GridBagConstraints c = new GridBagConstraints(); final int realPadding = (padding / 2); c.gridheight = 1; c.gridwidth = 1; c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; c.insets = new Insets(realPadding, realPadding, realPadding, realPadding); for (int i = 0; i < (rowCount * colCount); i++) { final int x = (i % colCount); final int y = (i / colCount); c.gridx = x; c.gridy = y; parent.add(components.get(i), c); } }
From source file:Main.java
public static void addComponentToGridBagLayout(Container cont, GridBagLayout gbl, int x, int y, int width, int height, double weightx, double weighty, Component component) { GridBagConstraints gbc = new GridBagConstraints(); if (y == 0)//from w w w . jav a 2s .com gbc.insets = new Insets(8, 6, 4, 6); else gbc.insets = new Insets(4, 6, 4, 6); gbc.fill = GridBagConstraints.BOTH; gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = width; gbc.gridheight = height; gbc.weightx = weightx; gbc.weighty = weighty; gbl.setConstraints(component, gbc); cont.add(component); }
From source file:Main.java
/** * Creates a panel that contains all of the components on top of each other in north, * and tries to make them as small as possible (probably by using getPreferredSize()). * * @deprecated use proper layout, usually no need to use such complex/ugly layouting *///from w w w . j a va2 s . co m public static JPanel combineInNorth(JComponent[] components) { JPanel result = new JPanel(); if (components.length == 0) { return result; } result.setLayout(new BorderLayout()); JPanel contentPanel = new JPanel(); result.add(contentPanel, BorderLayout.NORTH); contentPanel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.gridx = 0; constraints.weightx = 1.0; constraints.fill = GridBagConstraints.HORIZONTAL; for (int i = 0; i < components.length; i++) { contentPanel.add(components[i], constraints); } if (result.isVisible()) result.doLayout(); return result; }