本文整理了Java中javax.swing.JComboBox.addItem()
方法的一些代码示例,展示了JComboBox.addItem()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JComboBox.addItem()
方法的具体详情如下:
包路径:javax.swing.JComboBox
类名称:JComboBox
方法名:addItem
暂无
代码示例来源:origin: log4j/log4j
protected JComboBox createLogLevelCombo() {
JComboBox result = new JComboBox();
Iterator levels = getLogLevels();
while (levels.hasNext()) {
result.addItem(levels.next());
}
result.setSelectedItem(_leastSevereDisplayedLogLevel);
result.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox box = (JComboBox) e.getSource();
LogLevel level = (LogLevel) box.getSelectedItem();
setLeastSevereDisplayedLogLevel(level);
}
});
result.setMaximumSize(result.getPreferredSize());
return result;
}
代码示例来源:origin: stackoverflow.com
JComboBox box = new JComboBox();
box.addItem("One");
box.addItem("Two");
box.addItem("Three");
box.addItem("Four");
frame.getContentPane().add(box);
frame.pack();
frame.setVisible(true);
代码示例来源:origin: log4j/log4j
protected JToolBar createToolBar() {
JToolBar tb = new JToolBar();
tb.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
JComboBox fontCombo = new JComboBox();
JComboBox fontSizeCombo = new JComboBox();
_fontSizeCombo = fontSizeCombo;
fontCombo.addItem(fonts[j]);
fontCombo.setSelectedItem(_fontName);
fontSizeCombo.addItem("8");
fontSizeCombo.addItem("9");
fontSizeCombo.addItem("10");
fontSizeCombo.addItem("12");
fontSizeCombo.addItem("14");
fontSizeCombo.addItem("16");
fontSizeCombo.addItem("18");
fontSizeCombo.addItem("24");
fontSizeCombo.setSelectedItem(String.valueOf(_fontSize));
fontSizeCombo.addActionListener(
new ActionListener() {
tb.add(new JLabel(" Font: "));
tb.add(fontCombo);
tb.add(fontSizeCombo);
代码示例来源:origin: nodebox/nodebox
final JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
mainPanel.setBorder(new Theme.InsetsBorder(10, 10, 10, 10));
final JPanel formatPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 10, 10));
formatPanel.add(new JLabel("Format:"));
formatBox = new JComboBox<>();
formatBox.addItem("SVG");
formatBox.addItem("PNG");
formatBox.addItem("PDF");
formatBox.addItem("CSV");
formatBox.setSelectedItem("SVG");
formatPanel.add(formatBox);
final JPanel delimiterPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 10, 10));
delimiterPanel.add(new JLabel("Delimiter:"));
delimiterBox = new JComboBox<>();
delimiterBox.addItem(new Delimiter(',', ","));
delimiterBox.addItem(new Delimiter(';', ";"));
delimiterBox.addItem(new Delimiter(':', ":"));
delimiterBox.addItem(new Delimiter('\t', "Tab"));
delimiterBox.addItem(new Delimiter(' ', "Space"));
delimiterPanel.add(delimiterBox);
final JPanel quotesPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 10, 10));
quotesPanel.add(new JLabel("Quotes:"));
quotesBox = new JCheckBox("Escape output using quotes", true);
quotesPanel.add(quotesBox);
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* Layout the component
*/
@Override
public void layoutEditor() {
m_stepToBlockBox.setEditable(true);
StepManager sm = getStepToEdit().getStepManager();
List<StepManagerImpl> flowSteps =
getMainPerspective().getCurrentLayout().getFlow().getSteps();
for (StepManagerImpl smi : flowSteps) {
m_stepToBlockBox.addItem(smi.getName());
}
JPanel p = new JPanel(new BorderLayout());
p.setBorder(BorderFactory.createTitledBorder("Choose step to wait for"));
p.add(m_stepToBlockBox, BorderLayout.NORTH);
add(p, BorderLayout.CENTER);
String userSelected = ((Block) getStepToEdit()).getStepToWaitFor();
if (userSelected != null) {
m_stepToBlockBox.setSelectedItem(userSelected);
}
}
代码示例来源:origin: Blazemeter/jmeter-bzm-plugins
@Override
public void addUI(JComponent mainPanel, GridBagConstraints labelConstraints, GridBagConstraints editConstraints) {
addToPanel(mainPanel, labelConstraints, 0, 0, new JLabel("Type: ", JLabel.RIGHT));
addToPanel(mainPanel, editConstraints, 1, 0, rosterAction = new JComboBox<>());
rosterAction.addItem(Action.get_roster);
rosterAction.addItem(Action.add_item);
rosterAction.addItem(Action.delete_item);
addToPanel(mainPanel, labelConstraints, 0, 1, new JLabel("JID: ", JLabel.RIGHT));
addToPanel(mainPanel, editConstraints, 1, 1, rosterItem = new JTextField(20));
}
代码示例来源:origin: stackoverflow.com
final JComboBox combo = new JComboBox();
combo.addItem("Fast");
combo.addItem("Slow");
combo.addActionListener(new ActionListener() {
JPanel btnPanel = new JPanel(new FlowLayout());
btnPanel.add(run);
btnPanel.add(combo);
this.add(btnPanel, BorderLayout.SOUTH);
代码示例来源:origin: org.apache.jmeter/ApacheJMeter_http
/**
* Create a panel containing the implementation details
*
* @return the panel
*/
protected final JPanel getImplementationPanel(){
JPanel implPanel = new HorizontalPanel();
implPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
JMeterUtils.getResString("web_server_client"))); // $NON-NLS-1$
implPanel.add(new JLabel(JMeterUtils.getResString("http_implementation"))); // $NON-NLS-1$
httpImplementation.addItem("");// $NON-NLS-1$
implPanel.add(httpImplementation);
return implPanel;
}
代码示例来源:origin: ballerina-platform/ballerina-lang
private JComboBox<String> createComboBox(final JPanel panel, final String selected) {
final JComboBox<String> typeBox = new ComboBox<>();
final ConfigurableTypes[] types = ConfigurableTypes.values();
for (final ConfigurableTypes type : types) {
typeBox.addItem(type.getTyp());
}
typeBox.setSelectedItem(selected);
typeBox.addItemListener(e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
final int idx = getComponentIndex(panel);
if (e.getItem().equals(ConfigurableTypes.ARTIFACT.getTyp())) {
rootPanel.add(createArtifactRow("", "", "", ""), idx);
rootPanel.remove(panel);
rows.remove(idx);
} else if (e.getItem().equals(ConfigurableTypes.RAWCOMMAND.getTyp())) {
rootPanel.add(createCommandRow("", ""), idx);
rootPanel.remove(panel);
rows.remove(idx);
} else if (e.getItem().equals(ConfigurableTypes.EXE.getTyp())) {
rootPanel.add(createExeRow("", "", ""), idx);
rootPanel.remove(panel);
rows.remove(idx);
} else {
LOG.error("Unknown type : " + e.getItem());
}
}
});
return typeBox;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-debugger-common2
/** creates the combo box GUI in this option
*/
protected JPanel createComboBox() {
JPanel comboBoxPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
String[] labels = optionType.getValueLabels();
String[] values = optionType.getValues();
for (int i = 0; i < labels.length; i++) {
comboBox.addItem(labels[i]);
//if (currValue.equals(values[i]))
// comboBox.setSelectedItem(labels[i]);
}
comboBox.getAccessibleContext()
.setAccessibleDescription(optionType.getOptionDescription());
updateUI();
comboBoxPanel.add(comboBox);
//mainPanel.add(comboBoxPanel, BorderLayout.CENTER);
return comboBoxPanel;
}
代码示例来源:origin: winder/Universal-G-Code-Sender
@Override
synchronized public void restoreDefaults() throws Exception {
FirmwareUtils.restoreDefaults((String)controllerConfigs.getSelectedItem());
updatingCombo = true;
String selected = (String) controllerConfigs.getSelectedItem();
this.controllerConfigs.removeAllItems();
for (String item : configFiles.keySet()) {
this.controllerConfigs.addItem(item);
}
controllerConfigs.setSelectedItem(selected);
updatingCombo = false;
updateComponentsInternal(settings);
}
代码示例来源:origin: openpnp/openpnp
private void createUi() {
camerasPanel = new JPanel();
camerasCombo = new JComboBox();
camerasCombo.addActionListener(cameraSelectedAction);
setLayout(new BorderLayout());
camerasCombo.addItem(SHOW_NONE_ITEM);
add(camerasCombo, BorderLayout.NORTH);
add(camerasPanel);
}
代码示例来源:origin: pmd/pmd
private JPanel makeSettingsPanel(JButton browseButton, JButton goButton, JButton cxButton) {
JPanel settingsPanel = new JPanel();
GridBagHelper helper = new GridBagHelper(settingsPanel, new double[] { 0.2, 0.7, 0.1, 0.1 });
helper.addLabel("Root source directory:");
helper.addLabel("Language:");
for (int i = 0; i < LANGUAGE_SETS.length; i++) {
languageBox.addItem(String.valueOf(LANGUAGE_SETS[i][0]));
代码示例来源:origin: cytoscape.coreplugins/attribute-browser
private void initApplyToComboBox(final Container contentPane) {
applyToComboBox = new JComboBox();
final int selectedCellRow = table.getSelectedRow();
if (selectedCellRow >= 0)
applyToComboBox.addItem(ApplicationDomain.CURRENT_CELL);
final List<GraphObject> selectedGraphObjects = tableModel.getObjects();
if (selectedGraphObjects != null && !selectedGraphObjects.isEmpty())
applyToComboBox.addItem(ApplicationDomain.CURRENT_SELECTION);
applyToComboBox.addItem(ApplicationDomain.ENTIRE_ATTRIBUTE);
final Dimension widthAndHeight = applyToComboBox.getPreferredSize();
final Dimension desiredWidthAndHeight = new Dimension(180, 30);
applyToComboBox.setPreferredSize(desiredWidthAndHeight);
applyToComboBox.setMinimumSize(desiredWidthAndHeight);
applyToComboBox.setSize(desiredWidthAndHeight);
applyToComboBox.setMaximumSize(desiredWidthAndHeight);
contentPane.add(applyToComboBox);
applyToComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
applicationDomain = (ApplicationDomain)applyToComboBox.getSelectedItem();
}
});
applyToComboBox.setEditable(false);
applyToComboBox.setEnabled(false);
}
代码示例来源:origin: org.zaproxy/zap
@Override
public JComboBox<HtmlParameter.Type> getComboBoxTypes() {
JComboBox<HtmlParameter.Type> comboBoxTypes = new JComboBox<>();
comboBoxTypes.addItem(HtmlParameter.Type.form);
return comboBoxTypes;
}
}
代码示例来源:origin: gurkenlabs/litiengine
protected static void populateComboBoxWithSprites(JComboBox<JLabel> comboBox, Map<String, String> m) {
comboBox.removeAllItems();
for (Map.Entry<String, String> entry : m.entrySet()) {
JLabel label = new JLabel();
label.setText(entry.getKey());
Optional<Spritesheet> opt = Resources.spritesheets().tryGet(entry.getValue());
if (opt.isPresent() && opt.get().getTotalNumberOfSprites() > 0) {
BufferedImage scaled = opt.get().getPreview(24);
if (scaled != null) {
label.setIcon(new ImageIcon(scaled));
}
}
comboBox.addItem(label);
}
}
代码示例来源:origin: nodebox/nodebox
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
mainPanel.setBorder(new Theme.InsetsBorder(10, 10, 10, 10));
mainPanel.add(Box.createVerticalStrut(10));
JPanel directoryPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
directoryPanel.add(new JLabel("Directory: "));
directoryField = new JTextField(20);
directoryField.setEditable(false);
JPanel rangePanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 10, 0));
rangePanel.add(new JLabel("From:"));
fromField = new JTextField("1", 5);
rangePanel.add(fromField);
JPanel formatPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
formatPanel.add(new JLabel("Format:"));
formatBox = new JComboBox<>();
formatBox.addItem("SVG");
formatBox.addItem("PNG");
formatBox.addItem("PDF");
formatBox.setSelectedItem("SVG");
formatPanel.add(formatBox);
mainPanel.add(formatPanel);
代码示例来源:origin: stackoverflow.com
private static final JPanel cards = new JPanel(new CardLayout());
private static final JComboBox combo = new JComboBox();
private final String name;
this.setPreferredSize(new Dimension(320, 240));
this.setBackground(new Color(random.nextInt()));
this.add(new JLabel(name));
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
for (int i = 1; i < 9; i++) {
CardPanel p = new CardPanel("Panel " + String.valueOf(i));
combo.addItem(p);
cards.add(p, p.toString());
JPanel control = new JPanel();
combo.addActionListener(new ActionListener() {
control.add(combo);
f.add(cards, BorderLayout.CENTER);
f.add(control, BorderLayout.SOUTH);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* Sets the step to edit and configures the dialog
*
* @param step the step to edit
*/
@Override
public void setStepToEdit(Step step) {
copyOriginal(step);
try {
List<String> visiblePerspectives =
getGraphicalEnvironmentCommandHandler().performCommand(
GetPerspectiveNamesGraphicalCommand.GET_PERSPECTIVE_NAMES_KEY);
for (String s : visiblePerspectives) {
m_perspectivesCombo.addItem(s);
}
} catch (WekaException ex) {
showErrorDialog(ex);
}
String current = ((SendToPerspective) getStepToEdit()).getPerspectiveName();
m_perspectivesCombo.setSelectedItem(current);
JPanel p = new JPanel(new BorderLayout());
p.setBorder(BorderFactory
.createTitledBorder("Choose perspective to send to"));
p.add(m_perspectivesCombo, BorderLayout.NORTH);
createAboutPanel(step);
add(p, BorderLayout.CENTER);
}
代码示例来源:origin: camunda/camunda-bpm-platform
protected JToolBar createToolBar() {
JToolBar tb = new JToolBar();
tb.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
JComboBox fontCombo = new JComboBox();
JComboBox fontSizeCombo = new JComboBox();
_fontSizeCombo = fontSizeCombo;
fontCombo.addItem(fonts[j]);
fontCombo.setSelectedItem(_fontName);
fontSizeCombo.addItem("8");
fontSizeCombo.addItem("9");
fontSizeCombo.addItem("10");
fontSizeCombo.addItem("12");
fontSizeCombo.addItem("14");
fontSizeCombo.addItem("16");
fontSizeCombo.addItem("18");
fontSizeCombo.addItem("24");
fontSizeCombo.setSelectedItem(String.valueOf(_fontSize));
fontSizeCombo.addActionListener(
new ActionListener() {
tb.add(new JLabel(" Font: "));
tb.add(fontCombo);
tb.add(fontSizeCombo);
tb.addSeparator();
tb.addSeparator();
内容来源于网络,如有侵权,请联系作者删除!