public void addEntry(String name) { if (currentPanel == null) { newGroup("", false); } JLabel nameLabel = new JLabel(name); currentConstraints.gridy++; currentConstraints.gridx = 0; currentLayout.setConstraints(nameLabel, currentConstraints); currentPanel.add(nameLabel); JLabel valueLabel = new JLabel("", JLabel.RIGHT); currentConstraints.gridx = 1; currentLayout.setConstraints(valueLabel, currentConstraints); currentPanel.add(valueLabel); labelMap.put(name, new TwoLabelsContainer(nameLabel, valueLabel)); }
/** * adds a component to our gridbag layout */ private void addGridComponent(Container cont, Component comp, GridBagLayout mygb, int gridx, int gridy, int gridw, int gridh, int weightx, int weighty) { GridBagConstraints c = new GridBagConstraints(); c.gridx = gridx; c.gridy = gridy; c.gridwidth = gridw; c.gridheight = gridh; c.fill = GridBagConstraints.BOTH; c.weighty = weighty; c.weightx = weightx; c.anchor = GridBagConstraints.CENTER; mygb.setConstraints(comp, c); cont.add(comp); }
GridBagLayout gridBag = new GridBagLayout(); GridBagConstraints constraints; Insets insets; JLabel filenameLabel = new JLabel("Filename:"); filenameLabel.setLabelFor(filename); constraints = new GridBagConstraints( 0, 0, 1, 1, // x, y, width, height 0.0, 0.0, // weightx, weighty gridBag.setConstraints(filenameLabel, constraints); contentPane.add(filenameLabel); constraints = new GridBagConstraints( 1, 0, 1, 1, // x, y, width, height 1.0, 1.0, // weightx, weighty gridBag.setConstraints(filename, constraints); contentPane.add(filename); constraints = new GridBagConstraints( 0, 2, 2, 1, // x, y, width, height 1.0, 1.0, // weightx, weighty gridBag.setConstraints(okButton, constraints); contentPane.add(okButton);
private JSlider createSlider(JPanel panel, GridBagLayout gb, GridBagConstraints c, String title, Font font, int sliderRange, int start) { Utils.log2("createSlider range: " + sliderRange + ", start: " + start); JSlider s = new JSlider(JSlider.HORIZONTAL, 0, sliderRange, start); s.setPaintLabels(false); s.setPaintTicks(false); s.setBackground(Color.white); c.gridy++; c.insets = new Insets(2, 10, 0, 10); gb.setConstraints(s, c); panel.add(s); JLabel l = new JLabel(title); l.setBackground(Color.white); l.setFont(font); c.gridy++; c.insets = new Insets(0, 10, IJ.isMacOSX() ? 4 : 0, 0); JPanel p = new JPanel(); p.setBackground(Color.white); p.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); gb.setConstraints(p, c); p.add(l); panel.add(p); return s; }
/** * Add a component to a panel with the specified constraints. * @param panel the panel to add the component to. * @param g the <code>GridBagLayout</code> set on the panel. * @param c the constraints to apply to the component. * @param comp the component to add. */ protected void addLayoutComp(final JPanel panel, final GridBagLayout g, final GridBagConstraints c, final Component comp) { g.setConstraints(comp, c); panel.add(comp); }
}); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints constraints = new GridBagConstraints(); constraints.weightx = 1.0; constraints.weighty = 1.0; gridbag.setConstraints(scroll, constraints); dialog.add(scroll); constraints.fill = GridBagConstraints.NONE; constraints.weighty = 0.0; gridbag.setConstraints(okay, constraints); dialog.add(okay); gridbag.setConstraints(cancel, constraints); dialog.add(cancel); dialog.pack();
private void addDetailsComponent(Component c, int x, int y, int width, int height, double weightx, double weighty) { GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = width; gbc.gridheight = height; gbc.weightx = weightx; gbc.weighty = weighty; gbc.anchor = GridBagConstraints.NORTH; gbc.insets = new Insets(3, 3, 3, 3); detailsLayout.setConstraints(c, gbc); detailsPanel.add(c); } }
public void bottomPadding() { c.gridy = rows++; c.gridx = 0; c.anchor = GridBagConstraints.NORTHWEST; c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; JPanel space = new JPanel(); bl.setConstraints(space, c); add(space); }
public void addMessage(String text) { JLabel label = new JLabel(text); c.gridy = rows++; c.gridx = 0; c.anchor = GridBagConstraints.NORTHWEST; c.weightx = 1; c.weighty = 0; c.gridwidth = 2; c.fill = GridBagConstraints.NONE; bl.setConstraints(label, c); add(label); }
GridBagLayout layout = new GridBagLayout(); JPanel panel = new JPanel(layout); ... layout.setConstraints(myComponent, anotherConstraint); // do this for all the components you want to update panel.revalidate(); panel.repaint();
JLabel label = new JLabel("Filter Level:"); gridbag.setConstraints(label, c); add(label); label = new JLabel("Filter Thread:"); gridbag.setConstraints(label, c); add(label); label = new JLabel("Filter Logger:"); gridbag.setConstraints(label, c); add(label); gridbag.setConstraints(label, c); add(label); gridbag.setConstraints(label, c); add(label); priorities.setSelectedItem(lowest); aModel.setPriorityFilter(lowest); gridbag.setConstraints(priorities, c); add(priorities); priorities.setEditable(false); gridbag.setConstraints(threadField, c); add(threadField); gridbag.setConstraints(catField, c); add(catField);
private void addLabelColumn(int x,int y,GridBagLayout gbl, GridBagConstraints gbc, final String value) { JLabel modLabel=new JLabel(value); modLabel.setBorder(BorderFactory.createLineBorder(Color.black)); gbc.gridx=x; gbc.gridy=y; gbl.setConstraints(modLabel, gbc); table.add(modLabel); }
@Override public Component add(Component comp) { c.gridwidth = 2; c.gridx = 0; c.gridy = y; c.weightx = 1; gb.setConstraints(comp, c); internal.add(comp); ++y; return comp; }
public class CenteringPanel extends JPanel { public CenteringPanel(JComponent child) { GridBagLayout gbl = new GridBagLayout(); setLayout(gbl); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = GridBagConstraints.REMAINDER; gbl.setConstraints(child, c); add(child); } }
private void addDetailsComponent(Component c, int x, int y, int width, int height, double weightx, double weighty) { GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = width; gbc.gridheight = height; gbc.weightx = weightx; gbc.weighty = weighty; gbc.anchor = GridBagConstraints.NORTH; gbc.insets = new Insets(3, 3, 3, 3); detailsLayout.setConstraints(c, gbc); detailsPanel.add(c); } }
private static JPanel createReportPanel(final GridBagLayout gbl, final GridBagConstraints gbc) { JPanel reports = new JPanel(); reports.setBorder(BorderFactory.createTitledBorder(GUIConstants.REPORT)); reports.setLayout( new GridLayout(GUIConstants.REPORT_PANEL_LINES_NUMBER, GUIConstants.REPORT_PANEL_COLUMNS_NUMBER)); setGridBagConstraintsParameters(gbc, GUIConstants.REPORT_PANEL_CONSTRAINT_GRID_X, GUIConstants.REPORT_PANEL_CONSTRAINT_GRID_Y, GUIConstants.REPORT_PANEL_CONSTRAINT_WEIGHT_X, GUIConstants.REPORT_PANEL_CONSTRAINT_WEIGHT_Y, GUIConstants.REPORT_PANEL_CONSTRAINT_GRID_WIDTH, GUIConstants.REPORT_PANEL_CONSTRAINT_GRID_HEIGHT, GridBagConstraints.HORIZONTAL); gbl.setConstraints(reports, gbc); return reports; }
/** The left-side label of a field. */ private void addLabel(String label) { c.gridy = rows++; c.gridx = 0; JLabel l = new JLabel(label); c.anchor = GridBagConstraints.NORTHEAST; c.weightx = 1; c.weighty = 0; c.ipadx = 10; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; bl.setConstraints(l, c); add(l); }
/** * adds a component to our gridbag layout */ private void addGridComponent(Container cont, Component comp, GridBagLayout mygb, int gridx, int gridy, int gridw, int gridh, int weightx, int weighty) { GridBagConstraints c = new GridBagConstraints(); c.gridx = gridx; c.gridy = gridy; c.gridwidth = gridw; c.gridheight = gridh; c.fill = GridBagConstraints.BOTH; c.weighty = weighty; c.weightx = weightx; c.anchor = GridBagConstraints.CENTER; mygb.setConstraints(comp, c); cont.add(comp); }
gbc.anchor = GridBagConstraints.EAST; gbc.weightx = 0.5; JLabel rulenameLabel = new JLabel("Rule name : "); gbl.setConstraints(rulenameLabel, gbc); add(rulenameLabel); gbc.weightx = 0.5; gbc.anchor = GridBagConstraints.WEST; gbc.gridx = 1; gbl.setConstraints(rulenameField, gbc); add(rulenameField); gbc.anchor = GridBagConstraints.EAST; gbc.weightx = 0.5; JLabel rulemsgLabel = new JLabel("Rule msg : "); gbl.setConstraints(rulemsgLabel, gbc); add(rulemsgLabel); gbc.gridx = 1; gbc.anchor = GridBagConstraints.WEST; gbc.weightx = 0.5; gbl.setConstraints(rulemsgField, gbc); add(rulemsgField); gbc.anchor = GridBagConstraints.EAST; gbc.weightx = 0.5; JLabel ruledescLabel = new JLabel("Rule desc : "); gbl.setConstraints(ruledescLabel, gbc); add(ruledescLabel); gbc.gridx = 1;
public Component add(String label, String tip, Component comp) { JLabel labelComponent = new JLabel(label); if (tip != null) { labelComponent.setToolTipText(tip); } c.gridwidth = 1; c.gridx = 0; c.gridy = y; c.weightx = 0; gb.setConstraints(labelComponent, c); internal.add(labelComponent); c.gridx = 1; c.weightx = 1; gb.setConstraints(comp, c); internal.add(comp); ++y; return null; }