javax.swing.JComboBox.addActionListener()方法的使用及代码示例

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

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

JComboBox.addActionListener介绍

暂无

代码示例

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * <code>setUpChooser</code> retrieves all available display modes and
 * places them in a <code>JComboBox</code>. The resolution specified by
 * GameSettings is used as the default value.
 * 
 * @return the combo box of display modes.
 */
private JComboBox setUpResolutionChooser() {
  JComboBox resolutionBox = new JComboBox();
  resolutionBox.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      updateDisplayChoices();
    }
  });
  return resolutionBox;
}

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

private void initializeComponents (BillboardParticleBatch renderer) {
  alignCombo = new JComboBox();
  alignCombo.setModel(new DefaultComboBoxModel(AlignModeWrapper.values()));
  alignCombo.setSelectedItem(getAlignModeWrapper(renderer.getAlignMode()));
  alignCombo.addActionListener(new ActionListener() {
    public void actionPerformed (ActionEvent event) {
      AlignModeWrapper align = (AlignModeWrapper)alignCombo.getSelectedItem();
  sortCombo = new JComboBox();
  sortCombo.setModel(new DefaultComboBoxModel(SortMode.values()));
  sortCombo.setSelectedItem(getSortMode(renderer.getSorter()));
  sortCombo.addActionListener(new ActionListener() {
    public void actionPerformed (ActionEvent event) {
      SortMode mode = (SortMode)sortCombo.getSelectedItem();
  contentPanel.add(new JLabel("Align"), new GridBagConstraints(0, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(alignCombo, new GridBagConstraints(1, i++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(new JLabel("Use GPU"), new GridBagConstraints(0, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(useGPUBox, new GridBagConstraints(1, i++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(new JLabel("Sort"), new GridBagConstraints(0, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(sortCombo, new GridBagConstraints(1, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,

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

private JPanel makeTregexPatternArea() {
 recentTregexPatterns = new JComboBox<>(recentTregexPatternsModel);
 recentTregexPatterns.setMinimumSize(new Dimension(120, 24));
 recentTregexPatterns.addActionListener(this);
 JLabel recentLabel = new JLabel("Recent: ");
 JLabel patternLabel = new JLabel("Pattern: ");
 tregexPattern = new JTextArea();
 tregexPattern.setFocusTraversalKeysEnabled(true);
 JPanel tregexInput = new JPanel();
 tregexInput.setLayout(new GridBagLayout());
 GridBagConstraints c = new GridBagConstraints();
 c.fill = GridBagConstraints.BOTH;
 c.gridx = 0;
 c.gridy = 1;
 tregexInput.add(patternLabel,c);
 c.gridx = 1;
 c.weightx = 12.0;

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

private final JComboBox combo1 = new JComboBox(
  new String[]{"Course 1", "Course 2", "Course 3"});
private final JComboBox combo2 = new JComboBox();
private ComboBoxModel[] models = new ComboBoxModel[3];
  this.add(combo1);
  this.add(combo2);
  combo1.addActionListener(this);
  JFrame f = new JFrame("ComboTest");
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  f.add(this);
  f.pack();
  f.setLocationRelativeTo(null);
  f.setVisible(true);

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

JPanel jp_form_label = new JPanel(new GridLayout(5, 1, RESTView.BORDER_WIDTH, RESTView.BORDER_WIDTH));
jp_form_label.add(new JLabel("<html>Host: </html>"));
jp_form_label.add(new JLabel("<html>Realm: </html>"));
jp_form_label.add(new JLabel("<html>Username: <font color=red>*</font></html>"));
jp_form_label.add(new JLabel("<html>Password: </html>"));
JLabel jl_premptive = new JLabel("Preemptive?");
jp_form_label.add(jl_premptive);
JPanel jp_form_input = new JPanel(new GridLayout(5, 1, RESTView.BORDER_WIDTH, RESTView.BORDER_WIDTH));
jp_form_input.add(jtf_host);
jp_form_input.add(jtf_realm);
jp_form_input.add(jcb_preemptive);
JPanel jp_form = new JPanel(new BorderLayout());
jp_form.add(jp_form_label, BorderLayout.WEST);
jp_form.add(jp_form_input, BorderLayout.CENTER);
jcb_types.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent ae) {

代码示例来源:origin: net.java.abeille/abeille

public ComboEditor() {
  m_panel = new JPanel(new BorderLayout());
  m_panel.add(m_cbox, BorderLayout.CENTER);
  m_cbox.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
      setValue(m_cbox.getSelectedItem());
    }
  });
}

代码示例来源:origin: skylot/jadx

private SettingsGroup makeOtherGroup() {
  JComboBox<LangLocale> languageCbx = new JComboBox<>(NLS.getI18nLocales());
  for (LangLocale locale : NLS.getI18nLocales()) {
    if (locale.equals(settings.getLangLocale())) {
  languageCbx.addActionListener(e -> settings.setLangLocale((LangLocale) languageCbx.getSelectedItem()));

代码示例来源: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.addActionListener(
 fontSizeCombo.addActionListener(
   new ActionListener() {
    public void actionPerformed(ActionEvent e) {
 tb.add(new JLabel(" Font: "));
 tb.add(fontCombo);
 tb.add(fontSizeCombo);
 tb.addSeparator();
 tb.addSeparator();

代码示例来源:origin: nroduit/Weasis

private void addDisplayFormatComponent() {
    formatLabel = new JLabel(Messages.getString("ToolPanel.disp_format") + StringUtil.COLON); //$NON-NLS-1$
    this.add(formatLabel);

    formatCombo = new JComboBox<>(Format.values());
    formatCombo.setFocusable(false);
    formatCombo.setSelectedItem(view.getCurrentFormat());
    formatCombo.addActionListener(e -> view.setFormat((Format) formatCombo.getSelectedItem()));
    this.add(formatCombo);
  }
}

代码示例来源: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.addActionListener(
 fontSizeCombo.addActionListener(
   new ActionListener() {
    public void actionPerformed(ActionEvent e) {
 tb.add(new JLabel(" Font: "));
 tb.add(fontCombo);
 tb.add(fontSizeCombo);

代码示例来源:origin: worstcase/gumshoe

public StatisticChooser(StackGraphPanel graph) {
  super(new BorderLayout());
  this.graph = graph;
  statSelector.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      final String label = (String)statSelector.getSelectedItem();
      statCard.show(statOptions, label);
      // if user manually selects current displayed type,
      // keep them in sync if new type is loaded
      // otherwise leave it on user's selected type
      // so viewing stats live won't change dropdown while user choosing a stat
      updateWhenLoaded = label.equals(lastLoadedType);
    }
  });
  final JPanel statChooserPanel = stackWest(new JLabel("Select statistic for report type "), statSelector, new JLabel(":"));
  statOptions.setBorder(BorderFactory.createEmptyBorder(5, 10, 10, 10));
  statOptions.setLayout(statCard);
  for(String typeName : DataTypeHelper.getTypes()) {
    statOptions.add(DataTypeHelper.forType(typeName).getOptionEditor(), typeName);
  }
  stackIn(this, BorderLayout.NORTH, statChooserPanel, statOptions, flow(close));
}

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

public DateFormatView() {
 super("DateFormat", "Date format", "Format of the date");
 p = new JPanel();
 p.setLayout(new MigLayout());
 combobox = new JComboBox(new String[]{
   "HH:mm:ss", // 
   "HH:mm:ss.SSS",// 
   "dd-MM HH:mm:ss.SSS",// 
   "E HH:mm:ss", //
   "E HH:mm:ss.SS", //
   "MMM dd, HH:mm:ss",// 
 });
 addLabel("Date format", 'd', combobox);
 final JTextField exampleTextField = new JTextField(20);
 exampleTextField.setEditable(false);
 addLabel("Format example", 'e', exampleTextField);
 combobox.addActionListener(e -> exampleTextField.setText(new SimpleDateFormat((String) combobox.getSelectedItem()).format(new Date())));
}

代码示例来源:origin: h3xstream/http-script-generator

private void buildLanguageOptions(Container container, OPTION[] options,ActionListener languageChangeListener) {
  listLanguages = new JComboBox(options);
  listLanguages.setName(CMB_LANGUAGE);
  listLanguages.addActionListener(languageChangeListener);
  container.add(listLanguages,BorderLayout.NORTH);
}

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

expirationComboBox.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    JComboBox cb = (JComboBox) e.getSource();
toolBar.add(pauseLabel);
toolBar.add(Box.createHorizontalGlue());
toolBar.add(new JLabel("Clear after:"));
toolBar.add(expirationComboBox);

代码示例来源: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:");
    languageBox.addItem(String.valueOf(LANGUAGE_SETS[i][0]));
  languageBox.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {

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

reloadFileButton.setText("Reload File");
final JComboBox<ParseMode> modesCombobox = new JComboBox<>(ParseMode.values());
modesCombobox.setSelectedIndex(0);
modesCombobox.addActionListener(event -> {
  model.setParseMode((ParseMode) modesCombobox.getSelectedItem());
  reloadAction.actionPerformed(null);
});
final JLabel modesLabel = new JLabel("Modes:", SwingConstants.RIGHT);
final int leftIndentation = 10;
modesLabel.setBorder(BorderFactory.createEmptyBorder(0, leftIndentation, 0, 0));
final JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1, 2));
buttonPanel.add(openFileButton);
buttonPanel.add(reloadFileButton);
final JPanel modesPanel = new JPanel();
modesPanel.add(modesLabel);
modesPanel.add(modesCombobox);
final JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
mainPanel.add(buttonPanel);
mainPanel.add(modesPanel, BorderLayout.LINE_END);

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

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPanel gui = new JPanel(new BorderLayout(5,5));
gui.setBorder( new TitledBorder("BorderLayout(5,5)") );
JPanel plafComponents = new JPanel(
  new FlowLayout(FlowLayout.RIGHT, 3,3));
plafComponents.setBorder(
  plafNames[ii] = plafInfos[ii].getName();
final JComboBox plafChooser = new JComboBox(plafNames);
plafComponents.add(plafChooser);
plafComponents.add(pack);
plafChooser.addActionListener( new ActionListener(){
  public void actionPerformed(ActionEvent ae) {
    int index = plafChooser.getSelectedIndex();
gui.add(plafComponents, BorderLayout.NORTH);
    labels.add( new JLabel("Label " + ++labelCount) );
    frame.validate();
frame.setVisible(true);

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

private void initializeComponents (BillboardParticleBatch renderer) {
  alignCombo = new JComboBox();
  alignCombo.setModel(new DefaultComboBoxModel(AlignModeWrapper.values()));
  alignCombo.setSelectedItem(getAlignModeWrapper(renderer.getAlignMode()));
  alignCombo.addActionListener(new ActionListener() {
    public void actionPerformed (ActionEvent event) {
      AlignModeWrapper align = (AlignModeWrapper)alignCombo.getSelectedItem();
  sortCombo = new JComboBox();
  sortCombo.setModel(new DefaultComboBoxModel(SortMode.values()));
  sortCombo.setSelectedItem(getSortMode(renderer.getSorter()));
  sortCombo.addActionListener(new ActionListener() {
    public void actionPerformed (ActionEvent event) {
      SortMode mode = (SortMode)sortCombo.getSelectedItem();
  contentPanel.add(new JLabel("Align"), new GridBagConstraints(0, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(alignCombo, new GridBagConstraints(1, i++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(new JLabel("Use GPU"), new GridBagConstraints(0, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(useGPUBox, new GridBagConstraints(1, i++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(new JLabel("Sort"), new GridBagConstraints(0, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(sortCombo, new GridBagConstraints(1, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,

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

public MarkNoteFilter() {
 super(NAME, DESCRIPTION);
 noteComboBox.setBorder(BorderFactory.createTitledBorder("With note:"));
 noteComboBox.addActionListener(e -> listener.ifPresent(LogFilterValueChangeListener::valueChanged));
 markComboBox.setBorder(BorderFactory.createTitledBorder("Marked:"));
 markComboBox.addActionListener(e -> listener.ifPresent(LogFilterValueChangeListener::valueChanged));
 gui = new JPanel(new GridLayout(2, 1));
 gui.add(noteComboBox);
 gui.add(markComboBox);
}

代码示例来源:origin: senbox-org/snap-desktop

private JComboBox<String> createInsertComboBox(final String title, final String[] patterns) {
  ArrayList<String> itemList = new ArrayList<>();
  itemList.add(title);
  itemList.addAll(Arrays.asList(patterns));
  final JComboBox<String> comboBox = new JComboBox<>(itemList.toArray(new String[itemList.size()]));
  comboBox.setFont(insertCompFont);
  comboBox.setEditable(false);
  comboBox.setForeground(insertCompColor);
  comboBox.addActionListener(e -> {
    if (comboBox.getSelectedIndex() != 0) {
      insertCodePattern((String) comboBox.getSelectedItem());
      comboBox.setSelectedIndex(0);
    }
  });
  return comboBox;
}

相关文章

JComboBox类方法