java.awt.GridBagLayout.setConstraints()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(99)

本文整理了Java中java.awt.GridBagLayout.setConstraints()方法的一些代码示例,展示了GridBagLayout.setConstraints()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GridBagLayout.setConstraints()方法的具体详情如下:
包路径:java.awt.GridBagLayout
类名称:GridBagLayout
方法名:setConstraints

GridBagLayout.setConstraints介绍

[英]Sets the constraints for the specified component in this layout.
[中]设置此布局中指定零部件的约束。

代码示例

代码示例来源:origin: chewiebug/GCViewer

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));
}

代码示例来源:origin: javax.activation/activation

/**
 * 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); 
}

代码示例来源:origin: cmusphinx/sphinx4

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);

代码示例来源:origin: sc.fiji/TrakEM2_

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;
}

代码示例来源:origin: org.jppf/jppf-common-node

/**
 * 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);
}

代码示例来源:origin: stanfordnlp/CoreNLP

});
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();

代码示例来源:origin: org.openmuc/openiec61850

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);
  }
}

代码示例来源:origin: sc.fiji/TrakEM2_

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);
}

代码示例来源:origin: sc.fiji/TrakEM2_

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);
}

代码示例来源:origin: stackoverflow.com

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();

代码示例来源:origin: log4j/log4j

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);

代码示例来源:origin: net.sf.ingenias/editor

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);
}

代码示例来源:origin: org.appdapter/org.appdapter.lib.gui

@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;
}

代码示例来源:origin: stackoverflow.com

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);
  }
}

代码示例来源:origin: openmuc/openiec61850

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);
  }
}

代码示例来源:origin: org.verapdf.apps/gui

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;
}

代码示例来源:origin: sc.fiji/TrakEM2_

/** 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);
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * 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); 
}

代码示例来源:origin: pmd/pmd

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;

代码示例来源:origin: org.appdapter/org.appdapter.lib.gui

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;
}

相关文章