javax.swing.JPanel.add()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(11.3k)|赞(0)|评价(0)|浏览(235)

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

JPanel.add介绍

暂无

代码示例

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

protected JPanel createStatusArea() {
 JPanel statusArea = new JPanel();
 JLabel status =
   new JLabel("No log records to display.");
 _statusLabel = status;
 status.setHorizontalAlignment(JLabel.LEFT);
 statusArea.setBorder(BorderFactory.createEtchedBorder());
 statusArea.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
 statusArea.add(status);
 return (statusArea);
}

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

public void run () {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setSize(480, 320);
    frame.setLocationRelativeTo(null);
    JPanel panel = new JPanel();
    frame.getContentPane().add(panel);
    panel.add(new NewSlider(200, 100, 500, 0.1f, 150, 300));
    frame.setVisible(true);
  }
});

代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin

@Nullable
@Override
protected JComponent createCenterPanel() {
 JPanel panel = new JPanel(new BorderLayout());
 panel.add(myCommandTextField, BorderLayout.NORTH);
 return panel;
}

代码示例来源:origin: apache/ignite

/**
 * @param components Components.
 * @return Panel.
 */
private JPanel createPanel(JComponent... components) {
  JPanel panel = new JPanel();
  panel.setLayout(new FlowLayout());
  for (JComponent component : components)
    panel.add(component);
  return panel;
}

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

JPanel panel = new JPanel();
panel.add(new JLabel("Global"), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
  new Insets(0, 0, 0, 0), 0, 0));
panel.add(isGlobalCheckBox = new JCheckBox(), new GridBagConstraints(1, 0, 1, 1, 0, 0, 
  GridBagConstraints.WEST, GridBagConstraints.NONE,
  new Insets(0, 0, 0, 0), 0, 0));
contentPanel.add(panel,new GridBagConstraints(0, 1, 1, 1, 0, 0, 
  GridBagConstraints.WEST, GridBagConstraints.NONE,
  new Insets(0, 0, 0, 0), 0, 0));
contentPanel.add( magnitudePanel = new ScaledNumericPanel(editor, null, charTitle, "Strength", "In world units per second.", true), 
  new GridBagConstraints(0, 2, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(0, 0, 0, 6), 0, 0));
JPanel spacer = new JPanel();
spacer.setPreferredSize(new Dimension());
contentPanel.add(spacer, new GridBagConstraints(6, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
  new Insets(0, 0, 0, 0), 0, 0));

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

private void initializeComponents () {
    JPanel contentPanel = getContentPanel();
    {
      JLabel label = new JLabel("Value:");
      contentPanel.add(label, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE,
        new Insets(0, 0, 0, 6), 0, 0));
    }
    {
      valueSpinner = new JSpinner(new SpinnerNumberModel(new Float(0), new Float(-99999), new Float(99999), new Float(0.1f)));
      contentPanel.add(valueSpinner, new GridBagConstraints(1, 1, 1, 1, 1, 0, GridBagConstraints.WEST,
        GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    }
  }
}

代码示例来源:origin: ballerina-platform/ballerina-lang

private JButton createNewRowButton() {
  final JButton newRowButton = new JButton();
  newRowButton.setText("+");
  newRowButton.addActionListener(e -> rootPanel.add(createArtifactRow("", "", "", "")));
  return newRowButton;
}

代码示例来源:origin: kiegroup/optaplanner

private JComponent createTopButtonPanel() {
  JPanel buttonPanel = new JPanel(new GridLayout(1, 6));
  buttonPanel.add(new JButton(new ExpandNodesAction()));
  buttonPanel.add(new JButton(new CollapseNodesAction()));
  buttonPanel.add(new JButton(new MoveNodeAction(true)));
  buttonPanel.add(new JButton(new MoveNodeAction(false)));
  renameNodeButton = new JButton(new RenameNodeAction());
  renameNodeButton.setEnabled(false);
  buttonPanel.add(renameNodeButton);
  buttonPanel.add(new JButton(new SwitchLevelsAction(false)));
  return buttonPanel;
}

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

private void initializeComponents () {
    JPanel contentPanel = getContentPanel();
    {
      label = new JLabel("Value:");
      contentPanel.add(label, new GridBagConstraints(2, 2, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE,
        new Insets(0, 0, 0, 6), 0, 0));
    }
    {
      minSlider = new Slider(0, -99999, 99999, 1, -400, 400);
      contentPanel.add(minSlider, new GridBagConstraints(3, 2, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
        new Insets(0, 0, 0, 0), 0, 0));
    }
    {
      maxSlider = new Slider(0, -99999, 99999, 1, -400, 400);
      contentPanel.add(maxSlider, new GridBagConstraints(4, 2, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
        new Insets(0, 6, 0, 0), 0, 0));
    }
    {
      rangeButton = new JButton("<");
      rangeButton.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
      contentPanel.add(rangeButton, new GridBagConstraints(5, 2, 1, 1, 1.0, 0, GridBagConstraints.WEST,
        GridBagConstraints.NONE, new Insets(0, 1, 0, 0), 0, 0));
    }
  }
}

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

private void initializeComponents (String chartTitle) {
    JPanel contentPanel = getContentPanel();
    {
      chart = new Chart(chartTitle) {
        public void pointsChanged () {
          value.setTimeline(chart.getValuesX());
          value.setScaling(chart.getValuesY());
        }
      };
      chart.setPreferredSize(new Dimension(150, 62));
      contentPanel.add(chart, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH,
        new Insets(0, 0, 0, 0), 0, 0));
    }
    {
      expandButton = new JButton("+");
      expandButton.setBorder(BorderFactory.createEmptyBorder(4, 10, 4, 10));
      contentPanel.add(expandButton, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST,
        GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
    }
  }
}

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

private void uiLayout () {
  title.setLayout(new GridLayout(1, 2));
  
  minimize.setPreferredSize(new Dimension(50, 26));
  exit.setPreferredSize(new Dimension(50, 26));
  title.add(minimize);
  title.add(exit);
  topBar.setLayout(new GridLayout(1, 1));
  topBar.add(windowLabel, new GridBagConstraints(0, 0, 0, 0, 0, 0, NORTHWEST, VERTICAL, new Insets(0, 0, 0, 0), 0, 0));
  setLayout(new GridBagLayout());
  add(topBar, new GridBagConstraints(0, 0, 0, 0, 0, 0, NORTH, HORIZONTAL, new Insets(0, 0, 0, 100), 0, 10));
  add(title, new GridBagConstraints(0, 0, 0, 0, 0, 0, NORTHEAST, NONE, new Insets(0, 0, 0, 0), 0, 0));
  add(logo, new GridBagConstraints(0, 0, 1, 1, 1, 0, CENTER, HORIZONTAL, new Insets(40, 6, 6, 6), 0, 0));
  add(form, new GridBagConstraints(0, 1, 1, 1, 1, 0, CENTER, HORIZONTAL, new Insets(6, 6, 0, 6), 0, 0));
  add(buttonPanel, new GridBagConstraints(0, 2, 1, 1, 0, 0, CENTER, NONE, new Insets(0, 0, 0, 0), 0, 0));
  add(scrollPane, new GridBagConstraints(0, 3, 1, 1, 1, 1, CENTER, BOTH, new Insets(6, 6, 6, 6), 0, 0));
}

代码示例来源:origin: iluwatar/java-design-patterns

private void setup() {
 setLayout(new BorderLayout());
 JPanel panel = new JPanel();
 add(jl, BorderLayout.SOUTH);
 add(panel, BorderLayout.CENTER);
 panel.setLayout(new GridLayout(6, 2));
 panel.add(new JLabel("Name"));
 panel.add(jtFields[0]);
 panel.add(new JLabel("Contact Number"));
 panel.add(jtFields[1]);
 panel.add(new JLabel("Address"));
 panel.add(jtAreas[0]);
 panel.add(new JLabel("Deposit Number"));
 panel.add(jtFields[2]);
 panel.add(new JLabel("Order"));
 panel.add(jtAreas[1]);
 panel.add(clearButton);
 panel.add(processButton);
 clearButton.addActionListener(e -> {
  for (JTextArea i : jtAreas) {
   i.setText("");
 processButton.addActionListener(e -> {
  Order order = new Order(jtFields[0].getText(), jtFields[1].getText(), jtAreas[0].getText(), jtFields[2].getText(),
    jtAreas[1].getText());

代码示例来源:origin: alibaba/druid

private void addTable(ColumnData columnData) {
  ArrayList<ArrayList<LinkedHashMap<String, Object>>> data = columnData.getTableData();
  int i = 0;
  ArrayList<String> ids = columnData.getNames();
  for (ArrayList<LinkedHashMap<String, Object>> listNow : data) {
    JTable table = new JTable();
    tableModel = new DruidTableModel(listNow);
    table.setModel(tableModel);
    String id = ids.get(i);
    JPanel panelNow = new JPanel(new BorderLayout());
    panelNow.setBorder((TitledBorder) BorderFactory.createTitledBorder(KEY_WORD_IDENTITY + ":" + id));
    contentPanel.add(panelNow);
    panelNow.add(table.getTableHeader(), BorderLayout.NORTH);
    panelNow.add(table);
    table.getColumnModel().getColumn(0).setCellRenderer(new DruidTableCellRenderer());
    i++;
  }
}

代码示例来源:origin: wiztools/rest-client

public static JPanel getFlowLayoutLeftAlignedMulti(Component ... components) {
  JPanel jp = new JPanel();
  jp.setLayout(new FlowLayout(FlowLayout.LEFT));
  
  for(Component c: components) {
    jp.add(c);
  }
  
  return jp;
}

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

JPanel panel = new JPanel();
panel.add(new JLabel("Global"), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
  new Insets(0, 0, 0, 0), 0, 0));
panel.add(isGlobalCheckBox = new JCheckBox(), new GridBagConstraints(1, 0, 1, 1, 0, 0, 
  GridBagConstraints.WEST, GridBagConstraints.NONE,
  new Insets(0, 0, 0, 0), 0, 0));
contentPanel.add(panel,new GridBagConstraints(0, 1, 1, 1, 0, 0, 
  GridBagConstraints.WEST, GridBagConstraints.NONE,
  new Insets(0, 0, 0, 0), 0, 0));
contentPanel.add( magnitudePanel = new ScaledNumericPanel(editor, null, charTitle, "Strength", "In world units per second.", true), 
  new GridBagConstraints(0, 2, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(0, 0, 0, 6), 0, 0));
JPanel spacer = new JPanel();
spacer.setPreferredSize(new Dimension());
contentPanel.add(spacer, new GridBagConstraints(6, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
  new Insets(0, 0, 0, 0), 0, 0));

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

private void initializeComponents () {
    JPanel contentPanel = getContentPanel();
    {
      JLabel label = new JLabel("Value:");
      contentPanel.add(label, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE,
        new Insets(0, 0, 0, 6), 0, 0));
    }
    {
      valueSpinner = new JSpinner(new SpinnerNumberModel(new Float(0), new Float(-99999), new Float(99999), new Float(0.1f)));
      contentPanel.add(valueSpinner, new GridBagConstraints(1, 1, 1, 1, 1, 0, GridBagConstraints.WEST,
        GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    }
  }
}

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

contentPanel.add(chart, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH,
    new Insets(0, 0, 0, 0), 0, 0));
  expandButton = new JButton("+");
  expandButton.setBorder(BorderFactory.createEmptyBorder(4, 10, 4, 10));
  contentPanel.add(expandButton, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST,
    GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
expandButton.addActionListener(new ActionListener() {
  public void actionPerformed (ActionEvent event) {
    chart.setExpanded(!chart.isExpanded());

代码示例来源:origin: groovy/groovy-core

public void testComponentParent() {
  if (HeadlessTestSupport.isHeadless()) return;
  JPanel panel = new JPanel();
  JButton bean = new JButton();
  panel.add(bean);
  Object value = InvokerHelper.getProperty(bean, "parent");
  assertTrue(value != null);
}

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

private void initializeComponents () {
    JPanel contentPanel = getContentPanel();
    {
      label = new JLabel("Value:");
      contentPanel.add(label, new GridBagConstraints(2, 2, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE,
        new Insets(0, 0, 0, 6), 0, 0));
    }
    {
      minSlider = new Slider(0, -99999, 99999, 1, -400, 400);
      contentPanel.add(minSlider, new GridBagConstraints(3, 2, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
        new Insets(0, 0, 0, 0), 0, 0));
    }
    {
      maxSlider = new Slider(0, -99999, 99999, 1, -400, 400);
      contentPanel.add(maxSlider, new GridBagConstraints(4, 2, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
        new Insets(0, 6, 0, 0), 0, 0));
    }
    {
      rangeButton = new JButton("<");
      rangeButton.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
      contentPanel.add(rangeButton, new GridBagConstraints(5, 2, 1, 1, 1.0, 0, GridBagConstraints.WEST,
        GridBagConstraints.NONE, new Insets(0, 1, 0, 0), 0, 0));
    }
  }
}

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

public void run () {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setSize(480, 320);
    frame.setLocationRelativeTo(null);
    JPanel panel = new JPanel();
    frame.getContentPane().add(panel);
    panel.add(new NewSlider(200, 100, 500, 0.1f, 150, 300));
    frame.setVisible(true);
  }
});

相关文章

微信公众号

最新文章

更多

JPanel类方法