java.awt.Container.getLayout()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(126)

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

Container.getLayout介绍

[英]Gets the layout manager for this container.
[中]获取此容器的布局管理器。

代码示例

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

protected void wrapStringOnPanel(String message,
  Container container) {
 GridBagConstraints c = getDefaultConstraints();
 c.gridwidth = GridBagConstraints.REMAINDER;
 // Insets() args are top, left, bottom, right
 c.insets = new Insets(0, 0, 0, 0);
 GridBagLayout gbLayout = (GridBagLayout) container.getLayout();
 while (message.length() > 0) {
  int newLineIndex = message.indexOf('\n');
  String line;
  if (newLineIndex >= 0) {
   line = message.substring(0, newLineIndex);
   message = message.substring(newLineIndex + 1);
  } else {
   line = message;
   message = "";
  }
  Label label = new Label(line);
  label.setFont(DISPLAY_FONT);
  gbLayout.setConstraints(label, c);
  container.add(label);
 }
}

代码示例来源:origin: 4thline/cling

public void addGridComponent(Component component) {
  GridLayout l = (GridLayout) getContentPane().getLayout();
  // Make more sections if necessary
  int availableSections = l.getColumns() * l.getRows();
  if (availableSections == getContentPane().getComponentCount()) {
    getContentPane().setLayout(new GridLayout(l.getColumns() + 1, l.getRows() + 1));
  }
  getContentPane().add(component);
  validate();
}

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

for (int i = 0; i < 5; i++) {
  buttons[i] = new JButton(borderConstraints[i]);
  borderPanel.add(buttons[i], borderConstraints[i]);
contentPane.add(borderPanel);
for (int i = 5; i < 8; i++) {
  buttons[i] = new JButton(Integer.toString(i));
  flowPanel.add(buttons[i]);
contentPane.add(flowPanel);
  @Override
  public void actionPerformed(ActionEvent ae) {
    CardLayout cardLayout = (CardLayout) cardPanel.getLayout();
    cardLayout.next(cardPanel);

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

protected void wrapStringOnPanel(String message,
  Container container) {
 GridBagConstraints c = getDefaultConstraints();
 c.gridwidth = GridBagConstraints.REMAINDER;
 // Insets() args are top, left, bottom, right
 c.insets = new Insets(0, 0, 0, 0);
 GridBagLayout gbLayout = (GridBagLayout) container.getLayout();
 while (message.length() > 0) {
  int newLineIndex = message.indexOf('\n');
  String line;
  if (newLineIndex >= 0) {
   line = message.substring(0, newLineIndex);
   message = message.substring(newLineIndex + 1);
  } else {
   line = message;
   message = "";
  }
  Label label = new Label(line);
  label.setFont(DISPLAY_FONT);
  gbLayout.setConstraints(label, c);
  container.add(label);
 }
}

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

this.setPreferredSize(new Dimension(320, 240));
this.setBackground(new Color(random.nextInt()));
this.add(new JLabel(name));
  CardPanel p = new CardPanel("Panel " + String.valueOf(i));
  combo.addItem(p);
  cards.add(p, p.toString());
  public void actionPerformed(ActionEvent e) {
    JComboBox jcb = (JComboBox) e.getSource();
    CardLayout cl = (CardLayout) cards.getLayout();
    cl.show(cards, jcb.getSelectedItem().toString());
control.add(combo);
f.add(cards, BorderLayout.CENTER);
f.add(control, BorderLayout.SOUTH);

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

this.setPreferredSize(new Dimension(320, 240));
this.setBackground(new Color(random.nextInt()));
this.add(new JLabel(name));
for (int i = 1; i < 9; i++) {
  CardPanel p = new CardPanel("Panel " + String.valueOf(i));
  cards.add(p, p.toString());
control.add(new JButton(new AbstractAction("\u22b2Prev") {
    CardLayout cl = (CardLayout) cards.getLayout();
    cl.previous(cards);
    CardLayout cl = (CardLayout) cards.getLayout();
    cl.next(cards);

代码示例来源:origin: magefree/mage

GridBagLayout layout = (GridBagLayout) parent.getLayout();
    parent.add(otherPanel, gbc);

代码示例来源:origin: org.seamless/seamless-swing

/**
 * Adds a "middle" field component. Any component may be
 * used. The component will be stretched to take all of
 * the space between the label and the "last" field. All
 * "middle" fields in the layout will be the same width.
 */
public void addMiddleField(Component c, Container parent) {
  GridBagLayout gbl = (GridBagLayout) parent.getLayout();
  gbl.setConstraints(c, middleConstraints);
  parent.add(c);
}

代码示例来源:origin: org.seamless/seamless-swing

/**
 * Adds a field component. Any component may be used. The
 * component will be stretched to take the remainder of
 * the current row.
 */
public void addLastField(Component c, Container parent) {
  GridBagLayout gbl = (GridBagLayout) parent.getLayout();
  gbl.setConstraints(c, lastConstraints);
  parent.add(c);
}

代码示例来源:origin: org.seamless/seamless-swing

/**
 * Adds an arbitrary label component, starting a new row
 * if appropriate. The width of the component will be set
 * to the minimum width of the widest component on the
 * form.
 */
public void addLabel(Component c, Container parent) {
  GridBagLayout gbl = (GridBagLayout) parent.getLayout();
  gbl.setConstraints(c, labelConstraints);
  parent.add(c);
}

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

protected void add(Container container, Component component, GridBagConstraints constraints, int x, int y, int width, int height)
  {
    constraints.gridx = x;
    constraints.gridy = y;
    constraints.gridwidth = width;
    constraints.gridheight = height;
    LayoutManager layout = container.getLayout();
    if (layout != null && layout instanceof GridBagLayout)
    {
      ((GridBagLayout)layout).setConstraints(component, constraints);
    }
    container.add(component);
  }
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-platform-ui

private static void addComponent (Container container, Component component) {
  GridBagConstraints c = new GridBagConstraints();
  c.gridx = c.gridy = GridBagConstraints.RELATIVE;
  c.gridheight = c.gridwidth = GridBagConstraints.REMAINDER;
  c.fill = GridBagConstraints.BOTH;
  c.anchor = GridBagConstraints.NORTHWEST;
  c.weightx = c.weighty = 1.0;
  ((GridBagLayout)container.getLayout()).setConstraints (component,c);
  container.add (component);
}

代码示例来源:origin: dcaoyuan/nbscala

private static void addComponent (Container container, Component component) {
  GridBagConstraints c = new GridBagConstraints();
  c.gridx = c.gridy = GridBagConstraints.RELATIVE;
  c.gridheight = c.gridwidth = GridBagConstraints.REMAINDER;
  c.fill = GridBagConstraints.BOTH;
  c.anchor = GridBagConstraints.NORTHWEST;
  c.weightx = c.weighty = 1.0;
  ((GridBagLayout)container.getLayout()).setConstraints (component,c);
  container.add (component);
}

代码示例来源:origin: org.seamless/seamless-swing

public void addSeparator(Container parent) {
    JSeparator separator = new JSeparator();
    GridBagLayout gbl = (GridBagLayout) parent.getLayout();
    gbl.setConstraints(separator, separatorConstraints);
    parent.add(separator);
  }
}

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

String cardName = "college_choices";
Container parent = this.getParent();
parent.add(new CChoice(), cardName); 
CardLayout cl = (CardLayout)parent.getLayout(); 
cl.show(parent, cardName);

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

private void addGBRow(final Container container, final Component comp, final Component previous) {
  final GridBagLayout gb = (GridBagLayout) container.getLayout();
  GridBagConstraints c = null;
  if (null == previous) {
    c = new GridBagConstraints();
    c.anchor = GridBagConstraints.NORTHWEST;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridy = 0;
  } else {
    c = gb.getConstraints(previous);
    c.gridy += 1;
  }
  gb.setConstraints(comp, c);
  container.add(comp);
}

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-bu

public Pack packAs(Component _c,Component _d)
{
 Container p=_d.getParent();
 if(p.getLayout()!=this)
  throw new IllegalArgumentException("invalid layout");
 Constraint e=(Constraint)constraints_.get(_d);
 if(e==null) e=new Constraint();
 if(_c.getParent()!=p) p.add(_c,e);
 return new Pack(this,_c,e);
}

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-bu

public Pack packIn(Component _c,Container _p)
{
 if(_p.getLayout()!=this)
  throw new IllegalArgumentException("invalid layout");
 Constraint e=(Constraint)constraints_.get(_c);
 if(e==null) e=new Constraint();
 if(_c.getParent()!=_p) _p.add(_c,e);
 return new Pack(this,_c,e);
}

代码示例来源:origin: org.geotools/gt2-widgets-swing

/**
 * Add the specified editor. No editor must exists for the specified name prior to this
 * call. The editor will be bring on top of the card layout (i.e. will become the visible
 * panel).
 *
 * @param  name The editor name. Should be one of {@link #NUMBER}, {@link #KERNEL} and
 *         similar constants.
 * @param  editor The editor.
 * @param  scroll {@code true} if the editor should be wrapped into a {@link JScrollPane}
 *         prior its addition to the container.
 */
private void addEditor(final String name, Component editor, final boolean scroll) {
  if (editors.put(name, editor) != null) {
    throw new IllegalStateException(name); // Should not happen.
  }
  if (scroll) {
    editor = new JScrollPane(editor);
  }
  cards.add(editor, name);
  ((CardLayout) cards.getLayout()).show(cards, name);
}

代码示例来源:origin: otros-systems/otroslogviewer

public static void main(String[] args) {
 JFrame f = new JFrame("a");
 JToolBar bar = new JToolBar();
 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 f.getContentPane().setLayout(new FlowLayout());
 System.out.println(f.getContentPane().getLayout().getClass().getName());
 NavBox navBox = new NavBox();
 navBox.setSize(500, 40);
 navBox.setMaximumSize(new Dimension(500, 20));
 navBox.setMinimumSize(new Dimension(500, 20));
 f.getContentPane().add(bar);
 bar.add(navBox);
 bar.add(new JButton("G"));
 f.setSize(300, 60);
 f.setVisible(true);
}

相关文章

微信公众号

最新文章

更多

Container类方法