当前位置: 首页>>代码示例>>Java>>正文


Java JComboBox.addItemListener方法代码示例

本文整理汇总了Java中javax.swing.JComboBox.addItemListener方法的典型用法代码示例。如果您正苦于以下问题:Java JComboBox.addItemListener方法的具体用法?Java JComboBox.addItemListener怎么用?Java JComboBox.addItemListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JComboBox的用法示例。


在下文中一共展示了JComboBox.addItemListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ImagePicker

import javax.swing.JComboBox; //导入方法依赖的package包/类
public ImagePicker() {
  noImage = new JTextArea(1,10);
  noImage.setFont(FONT);
  noImage.setText("Double-click here to add new image");
  noImage.addMouseListener(this);
  noImage.setEditable(false);
  noImage.setLineWrap(true);
  noImage.setWrapStyleWord(true);
  noImage.setMinimumSize(new Dimension(15, 32));
  icon = new OpIcon();
  imageView = new JLabel(icon);
  imageView.addMouseListener(this);

  imageViewer = new JPanel(new BorderLayout());
  imageScroller = new ScrollPane(
    imageView,
    JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  imageViewer.add(imageScroller, BorderLayout.CENTER);

  select = new JComboBox(ArrayUtils.prepend(GameModule.getGameModule().getDataArchive().getImageNames(), NO_IMAGE));
  select.addItemListener(this);
  setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
  add(noImage);
  add(select);
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:27,代码来源:ImagePicker.java

示例2: addComboBoxToPanel

import javax.swing.JComboBox; //导入方法依赖的package包/类
private void addComboBoxToPanel() {
    JComboBox comboBox = new JComboBox();
    try {
        List<Food> foods = DataProcesser.getDefaultFoodList();
        for (Food f : foods) {
            comboBox.addItem(new ComboModel(f.getId(), f.getFood()));

        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    comboBox.addItemListener(new ItemChangedListener());

    panelHolder[xPos][yPos].add(comboBox);

    updateCoordinate();

    jPanel5.revalidate();
    jPanel5.repaint();
}
 
开发者ID:seyidkanan,项目名称:my-diploma-work,代码行数:22,代码来源:KnowledgeBaseFrame.java

示例3: addInputCombo

import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
 * Adds an input field to select from a ComboBox
 * @param text text to be shown on a label
 * @param property property to be changed in Defaults
 * @param cont container where input field must be added
 * @param values Map with internal value <-> showed value relations
 */
protected void addInputCombo(String text, final String property, Container cont, final Map<String, String> values) {
	JLabel label = new JLabel(text + ":");
	JComboBox combo = new JComboBox(values.values().toArray());
	combo.setName(property);
	label.setLabelFor(combo);
	combo.setSelectedItem(values.get(Defaults.get(property)));
	// Sets maximum size to minimal one, otherwise springLayout will stretch this
	combo.setMaximumSize(new Dimension(combo.getMaximumSize().width, combo.getMinimumSize().height));
	combo.addItemListener(new ItemListener() {
		public void itemStateChanged(ItemEvent e) {
			// As Map does not allows reverse mapping, scans the entire keyset to
			// find the key corresponding to a given object
			Object[] keys = values.keySet().toArray();
			for (Object key : keys) {
				if (values.get(key) == e.getItem()) {
					Defaults.set(property, (String) key);
				}
			}
		}
	});
	cont.add(label);
	cont.add(combo);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:31,代码来源:DefaultsEditor.java

示例4: addChoice

import javax.swing.JComboBox; //导入方法依赖的package包/类
/** Create a choice menu.
 *  @param name The name used to identify the entry (when calling get).
 *  @param label The label to attach to the entry.
 *  @param values The list of possible choices.
 *  @param defaultChoice Default choice.
 *  @param editable True if an arbitrary choice can be entered, in addition
 *   to the choices in values.
 *  @param background The background color for the editable part.
 */
public void addChoice(
        String name,
        String label,
        String[] values,
        String defaultChoice,
        boolean editable,
        Color background) {
    JLabel lbl = new JLabel(label + ": ");
    lbl.setBackground(_background);
    JComboBox combobox = new JComboBox(values);
    combobox.setEditable(editable);
    // FIXME: Typical of Swing, the following does not set
    // the background color.  How does one set the background
    // color?
    combobox.setBackground(background);
    combobox.setSelectedItem(defaultChoice);
    _addPair(name, lbl, combobox, combobox);
    // Add the listener last so that there is no notification
    // of the first value.
    combobox.addItemListener(new QueryItemListener(name));
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:31,代码来源:Query.java

示例5: getFilterChooser

import javax.swing.JComboBox; //导入方法依赖的package包/类
private JComboBox<Filter> getFilterChooser() {
    if (this.filterChooser == null) {
        this.filterListening = true;
        final JComboBox<Filter> result = this.filterChooser = new JComboBox<>(Filter.values());
        result.setMaximumSize(new Dimension(result.getPreferredSize().width, 1000));
        result.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (LTSDisplay.this.filterListening) {
                    doFilterLTS();
                }
            }
        });
    }
    return this.filterChooser;
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:17,代码来源:LTSDisplay.java

示例6: initializeChooseColumnDialog

import javax.swing.JComboBox; //导入方法依赖的package包/类
private void initializeChooseColumnDialog( String input ) {
	String tempURLString = null;
	if ( hole.getLeg() < 100 ) {
		tempURLString = DSDP.DSDP_PATH + input + "/" + hole.toString() + "-" + input + ".txt";
	}
	else {
		tempURLString = DSDP.DSDP_PATH + "ODP_" + input + "/" + hole.toString() + "-" + input + ".txt";
	}
	try {
		DensityBRGTable tempTable = new DensityBRGTable(tempURLString);
		selectSedimentDialog = new JDialog(dsdpF);
		selectSedimentDialog.setTitle("Select Column");
		selectSedimentDialog.addWindowListener(this);
		
		selectAddColumnCB = new JComboBox();
		selectAddColumnCB.addItem("Select Column");
		for ( int i = 1; i < tempTable.headings.length; i++ ) {
			selectAddColumnCB.addItem(tempTable.headings[i]);
		}
		selectAddColumnCB.addItemListener(this);
		selectSedimentDialog.add(selectAddColumnCB);
		selectSedimentDialog.pack();
		selectSedimentDialog.setSize( 195, 100 );
		selectSedimentDialog.setLocation( selectSedimentDialogX, selectSedimentDialogY );
		selectSedimentDialog.setVisible(true);
	} catch (IOException ioe) {
		ioe.printStackTrace();
	}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:30,代码来源:DSDPDemo.java

示例7: ComboParameter

import javax.swing.JComboBox; //导入方法依赖的package包/类
public ComboParameter(JComboBox combo, String parameter, String encoding) {
    super(parameter, encoding);
    this.combo = combo;
    combo.setModel(new DefaultComboBoxModel());
    combo.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            fireStateChanged();
        }
    });
    original = (ParameterValue) combo.getSelectedItem();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:QueryParameter.java

示例8: initializeCombo

import javax.swing.JComboBox; //导入方法依赖的package包/类
private void initializeCombo() {
    boolean hasExistingRepositories = (existingRepositories != null)
                                      && (existingRepositories.length != 0);
    boolean hasBugtrackingConnectors = (bugtrackingConnectors != null)
                                       && (bugtrackingConnectors.length != 0);

    if (!hasExistingRepositories && !hasBugtrackingConnectors) {
        throw new IllegalStateException("No data for the combo-box."); //NOI18N
    }

    String newConnectionFormatString
                = (bugtrackingConnectorDisplayFormat != null)
                  ? bugtrackingConnectorDisplayFormat
                  : NbBundle.getMessage(
                            ComboItemsRenderer.class,
                            "NewBugtrackingRepositoryConnection");  //NOI18N

    combo = new JComboBox(joinArrays(existingRepositories,
                                     createRepositoryInfos(bugtrackingConnectors)));
    combo.setRenderer(new ComboItemsRenderer(combo.getRenderer(),
                                             newConnectionFormatString));
    //combo.setEditable(false);

    if (repoToPreselect != null) {
        combo.setSelectedItem(repoToPreselect);
    }
    itemSelected(combo.getSelectedItem());
    combo.addItemListener(this);
    combo.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(RepositorySelectorBuilder.class, "RepositorySelectorBuilder.combo.accessibleDescription")); // NOI18N

    if (label != null) {
        bindLabelToCombo();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:RepositorySelectorBuilder.java

示例9: createOperatorCombo

import javax.swing.JComboBox; //导入方法依赖的package包/类
private JComboBox createOperatorCombo(final PropertyTable propertyTable) {
	List<Operator> allInnerOps = parentOperator.getAllInnerOperators();
	Vector<String> allOpNames = new Vector<String>();
	Iterator<Operator> i = allInnerOps.iterator();
	while (i.hasNext()) {
		allOpNames.add(i.next().getName());
	}
	Collections.sort(allOpNames);
	final JComboBox combo = new JComboBox(allOpNames);
	combo.addItemListener(new ItemListener() {

		@Override
		public void itemStateChanged(ItemEvent e) {
			String operatorName = (String) combo.getSelectedItem();
			panel.remove(parameterCombo);
			parameterCombo = createParameterCombo(operatorName, propertyTable);
			panel.add(parameterCombo);
			fireParameterChangedEvent();
			fireEditingStopped();
		}
	});
	if (combo.getItemCount() == 0) {
		combo.addItem("add inner operators");
	} else {
		combo.setSelectedIndex(0);
	}
	return combo;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:29,代码来源:ParameterValueKeyCellEditor.java

示例10: createParameterCombo

import javax.swing.JComboBox; //导入方法依赖的package包/类
private JComboBox createParameterCombo(String operatorName, PropertyTable propertyTable) {
	JComboBox combo = new JComboBox();

	Operator operator = process.getOperator((String) operatorCombo.getSelectedItem());
	if (operator != null) {
		Iterator<ParameterType> i = operator.getParameters().getParameterTypes().iterator();
		while (i.hasNext()) {
			combo.addItem(i.next().getKey());
		}
	}

	if (combo.getItemCount() == 0) {
		combo.addItem("no parameters");
	}

	combo.addItemListener(new ItemListener() {

		@Override
		public void itemStateChanged(ItemEvent e) {
			fireParameterChangedEvent();
			fireEditingStopped();
		}
	});

	combo.setSelectedIndex(0);

	return combo;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:29,代码来源:ParameterValueKeyCellEditor.java

示例11: createPortNameCombo

import javax.swing.JComboBox; //导入方法依赖的package包/类
private JComboBox<String> createPortNameCombo() {
    final JComboBox <String> ret = new JComboBox<>( new SerialPortComboModel(model) );
    ret.addItemListener( (e) -> {            
        if ( e.getStateChange() == ItemEvent.SELECTED ) {
            model.setCurrentPortName( e.getItem().toString() );
        } else {
            model.setCurrentPortName( null );
        }
    });
    ret.setSelectedItem( model.getCurrentPortName() );
    return ret;
}
 
开发者ID:chipKIT32,项目名称:chipKIT-importer,代码行数:13,代码来源:SerialMonitorConfigPane.java

示例12: createSaveBox

import javax.swing.JComboBox; //导入方法依赖的package包/类
protected Component createSaveBox() {
	save = new JComboBox(saveOptions);
	save.addActionListener(this);
	save.addItemListener(this);
	save.addPopupMenuListener(this);
	save.setActionCommand("save");
	return save;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:9,代码来源:CustomDB.java

示例13: createParameterCombo

import javax.swing.JComboBox; //导入方法依赖的package包/类
private JComboBox<String> createParameterCombo( String[] values, String selectedValue, Consumer<String> modelSetter ) {
    JComboBox <String> ret = new JComboBox<>( values );
    ret.setSelectedItem( selectedValue );
    ret.addItemListener( (e) -> {
        if ( e.getStateChange() == ItemEvent.SELECTED ) {
            modelSetter.accept(e.getItem().toString());
        }
    });
    parameterCombos.add(ret);
    return ret;
}
 
开发者ID:chipKIT32,项目名称:chipKIT-importer,代码行数:12,代码来源:SerialMonitorConfigPane.java

示例14: showFPSConfigPopup

import javax.swing.JComboBox; //导入方法依赖的package包/类
public void showFPSConfigPopup() {
    int sysFPS = Runner.externalFPS, currentFPS = Runner.getFpsTarget();
    JFrame fpsConfigFrame = new JFrame("Refresh Rate Config");
    JPanel fpsConfigPanel = new JPanel();
    JLabel oldFPSLabel = new JLabel("old settings: foreground: " + sysFPS + " hz | background: " + currentFPS
            + " hz (" + Runner.getMsDelay() + "ms delay)");
    JLabel newFPSLabel = new JLabel("new settings: background: ");

    // TODO
    fpsConfigFrame.setSize(400, 200);
    JComboBox<String> fpsComboBox = new JComboBox<>();
    fpsComboBox.addItem("[select target refresh rate]");
    fpsComboBox.addItem("3 hz (GridWorld default)");
    fpsComboBox.addItem("10 hz");
    fpsComboBox.addItem("24 hz (cinematic)");
    fpsComboBox.addItem("60 hz");
    fpsComboBox.addItem("120 hz");
    fpsComboBox.addItem("144 hz");
    fpsComboBox.addItem("custom fps target");
    fpsComboBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                switch ((String) e.getItem()) {
                    case "3 hz (GridWorld default)":
                        Runner.setFpsTarget(3);
                        break;
                    case "10 hz":
                        Runner.setFpsTarget(10);
                        break;
                    case "20 hz (recommended)":
                        Runner.setFpsTarget(20);
                        break;
                    case "60 hz":
                        Runner.setFpsTarget(60);
                        break;
                    case "120 hz":
                        Runner.setFpsTarget(120);
                        break;
                    case "144 hz":
                        Runner.setFpsTarget(144);
                        break;
                    default:
                        try {
                            Runner.setFpsTarget(
                                    Integer.parseInt(JOptionPane.showInputDialog("set custom target FPS:")));
                        } catch (Exception e2) {
                            JOptionPane.showMessageDialog(null,
                                    "Error: bad fps target\nfps target must be integer in range [1,1000]",
                                    "Bad FPS target", 0, null);
                        }
                }
            }
            setTitle("AdvanceWars GridWorld (" + Runner.getFpsTarget() + "hz) : player "
                    + Runner.getTurnPlayer().id);
            fpsConfigFrame.dispose();
        }
    });

    fpsConfigPanel.add(oldFPSLabel);
    fpsConfigPanel.add(newFPSLabel);
    fpsConfigPanel.add(fpsComboBox);
    fpsConfigFrame.add(fpsConfigPanel);
    fpsConfigFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    fpsConfigFrame.setVisible(true);
}
 
开发者ID:CBSkarmory,项目名称:AWGW,代码行数:66,代码来源:WorldFrame.java

示例15: initComponents

import javax.swing.JComboBox; //导入方法依赖的package包/类
private void initComponents() {
    setLayout(new BorderLayout(4, 0));
    setBorder(new EmptyBorder(0, 2, 0, 8));
    setOpaque(false);
    setFocusTraversalPolicyProvider(true);
    setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
        @Override
        public Component getDefaultComponent(Container aContainer) {
            if (!SwingUtilities.isEventDispatchThread()) {
                return null;
            }
            final EditorCookie ec = actionContext.lookup(
                    EditorCookie.class);
            if (ec != null) {
                JEditorPane[] panes = ec.getOpenedPanes();
                if (panes != null) {
                    for (JEditorPane pane : panes) {
                        if (pane.isShowing()) {
                            return pane;
                        }
                    }
                }
            }

            return null;
        }
   });

    combo = new JComboBox();
    combo.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            DatabaseConnection dbconn = (DatabaseConnection)combo.getSelectedItem();
            combo.setToolTipText(dbconn != null ? dbconn.getDisplayName() : null);
        }
    });
    combo.setOpaque(false);
    combo.setModel(new DefaultComboBoxModel(
            new String[] { NbBundle.getMessage(ToolbarPresenter.class, "ConnectionAction.ToolbarPresenter.LoadingConnections") }));

    combo.setRenderer(new DatabaseConnectionRenderer());
    String accessibleName = NbBundle.getMessage(ConnectionAction.class, "LBL_DatabaseConnection");
    combo.getAccessibleContext().setAccessibleName(accessibleName);
    combo.getAccessibleContext().setAccessibleDescription(accessibleName);
    combo.setPreferredSize (new Dimension (400, combo.getPreferredSize ().height));

    add(combo, BorderLayout.CENTER);

    comboLabel = new JLabel();
    Mnemonics.setLocalizedText(comboLabel, NbBundle.getMessage(ConnectionAction.class, "LBL_ConnectionAction"));
    comboLabel.setOpaque(false);
    comboLabel.setLabelFor(combo);
    add(comboLabel, BorderLayout.WEST);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:55,代码来源:ConnectionAction.java


注:本文中的javax.swing.JComboBox.addItemListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。