本文整理汇总了Java中javax.swing.JComboBox.getSelectedItem方法的典型用法代码示例。如果您正苦于以下问题:Java JComboBox.getSelectedItem方法的具体用法?Java JComboBox.getSelectedItem怎么用?Java JComboBox.getSelectedItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JComboBox
的用法示例。
在下文中一共展示了JComboBox.getSelectedItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: askFont
import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
* Asks the user to choose a font; returns "" if the user cancels the
* request.
*/
public synchronized static String askFont() {
if (allFonts == null)
allFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
JComboBox jcombo = new OurCombobox(allFonts);
Object ans = show("Font", JOptionPane.INFORMATION_MESSAGE, new Object[] {
"Please choose the new font:", jcombo
}, new Object[] {
"Ok", "Cancel"
}, "Cancel");
Object value = jcombo.getSelectedItem();
if (ans == "Ok" && (value instanceof String))
return (String) value;
else
return "";
}
示例2: setItems
import javax.swing.JComboBox; //导入方法依赖的package包/类
public static void setItems(JComboBox comboBox, Object[] items) {
Object selected = comboBox.getSelectedItem();
comboBox.removeAllItems();
for (int i = 0; i < items.length; i++) {
comboBox.insertItemAt(items[i], i);
}
if (items.length > 0) {
comboBox.setSelectedIndex(0);
}
if (selected != null) {
comboBox.setSelectedItem(selected);
}
}
示例3: createGraphFromInterfaceProperties
import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
* Create a graph from interface properties
* @return a created graph from interface properties
*/
protected Graph createGraphFromInterfaceProperties(JComboBox cb){
GraphFactory factory = (GraphFactory) cb.getSelectedItem();
if(!factory.getNeededProperties().isEmpty()){
int np = propertiesPanel.getComponentCount();
int i=0;
while (i<np){
JLabel label = (JLabel)propertiesPanel.getComponent(i);
i++;
JTextField value = (JTextField)propertiesPanel.getComponent(i);
i++;
DefaultValueTypeProperty newDvt = (DefaultValueTypeProperty)(factory.getNeededProperties()).get(label.getText());
newDvt.setValue(value.getText());
}
}
Graph g = factory.createGraph(factory.getNeededProperties());
return g;
}
示例4: langComboBoxActionPerformed
import javax.swing.JComboBox; //导入方法依赖的package包/类
private void langComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_langComboBoxActionPerformed
JComboBox jComboBox = (JComboBox) evt.getSource();
String lang = (String) jComboBox.getSelectedItem();
String langsTemp = langsTextField.getText();
if (langsTemp.equals("")) {
langsTextField.setText(lang);
langsTemp = lang;
} else {
if (langsTemp.contains(lang)) {
String tempLangs1 = langsTemp.replace("," + lang, "");
String tempLangs2 = tempLangs1.replace(lang + ",", "");
String tempLangs3 = tempLangs2.replace(lang, "");
langsTemp = tempLangs3;
langsTextField.setText(tempLangs3);
} else {
langsTextField.setText(langsTemp + "," + lang);
langsTemp = langsTemp + "," + lang;
}
}
System.out.println("Selected langs: " + langsTemp);
langs = langsTemp;
}
示例5: actionPerformed
import javax.swing.JComboBox; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox) e.getSource();
if (e.getActionCommand().equals("year")) {
selectedYear = (String) cb.getSelectedItem();
}
else if (e.getActionCommand().equals("broker")) {
brokerList.updateSelectedBroker();
updateStocks(brokerList.getSelectedBroker(), selectedTransaction);
}
else if (e.getActionCommand().equals("transaction")) {
selectedTransaction = (String) cb.getSelectedItem();
updateStocks(brokerList.getSelectedBroker(), selectedTransaction);
}
else if (e.getActionCommand().equals("name")) {
selectedName = (String) cb.getSelectedItem();
}
update();
}
示例6: getDump
import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
* Returns information about component.
*/
@Override
public Hashtable<String, Object> getDump() {
Hashtable<String, Object> result = super.getDump();
JComboBox<?> jComboBox = (JComboBox<?>) getSource();
Object selectedItem = jComboBox.getSelectedItem();
if (selectedItem != null) {
result.put(TEXT_DPROP, selectedItem.toString());
}
int itemCount = jComboBox.getItemCount();
String[] items = new String[itemCount];
for (int i = 0; i < itemCount; i++) {
if (jComboBox.getItemAt(i) != null) {
items[i] = jComboBox.getItemAt(i).toString();
}
}
addToDump(result, ITEM_PREFIX_DPROP, items);
return result;
}
示例7: actionPerformed
import javax.swing.JComboBox; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
JComboBox<Integer> cb = (JComboBox<Integer>) e.getSource();
Integer selectedYear = (Integer) cb.getSelectedItem();
setYearData(selectedYear);
}
示例8: actionPerformed
import javax.swing.JComboBox; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox) e.getSource();
JFrame frame = (JFrame) cb.getParent().getParent().getParent().getParent();
Pair<Procedure, Integer> proc = (Pair<Procedure, Integer>) cb.getSelectedItem();
MarkovGraph g = partitionGraphs.get(proc);
assert (g != null);
GraphVisualizationPanel<MarkovVertex, MarkovEdge> graph_panel = MarkovViewer.getPanel(g);
graph_panel.add(cb);
frame.setContentPane(graph_panel);
frame.setBounds(50, 50, 500, 500);
frame.setVisible(true);
}
示例9: popupMenuWillBecomeVisible
import javax.swing.JComboBox; //导入方法依赖的package包/类
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
// GMA 1.4.8: Now check which combo box event is coming from
if ( e.getSource() == box ) {
// ***** Changed by A.K.M. 6/23/06 *****
// setPrototypeDisplayValue restricts the size of the box to a fixed
// length of eight characters
box.setPrototypeDisplayValue("WWWWWWWW");
// The popup listener adjusts the size of the popup to match the size
// of the text being displayed
JComboBox tempBox = (JComboBox) e.getSource();
Object comp = tempBox.getUI().getAccessibleChild(tempBox, 0);
if (!(comp instanceof JPopupMenu)) {
return;
}
JComponent scrollPane = (JComponent) ((JPopupMenu) comp).getComponent(0);
Dimension size = scrollPane.getPreferredSize();
UnknownDataSet tester1 = (UnknownDataSet)tempBox.getSelectedItem();
CustomBRGTable.setReverseYAxis(false);
CustomBRGTable.setIgnoreZeros(false);
// 6.5 is a hardcoded value that approximates the size of a
// character in pixels
// TODO: Find exact size of text in pixels and adjust
// size.width accordingly
if (tester1 != null) {
if (maxDBNameLength < tester1.desc.name.length()) {
maxDBNameLength = tester1.desc.name.length();
}
size.width = (int)(maxDBNameLength * 6.5);
scrollPane.setPreferredSize(size);
}
// ***** Changed by A.K.M. 6/23/06 *****
}
}
示例10: actionPerformed
import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
*
*/
@Override
public void actionPerformed(ActionEvent e)
{
String cmd = e.getActionCommand();
if (cmd.endsWith("Change"))
{
JComboBox<?> cb = (JComboBox<?>)e.getSource();
Object o = cb.getSelectedItem();
if (cmd.startsWith("event"))
{
DataEntry.state.setCurrentEvent((Event)o);
Messenger.sendEvent(MT.EVENT_CHANGED, null);
Prefs.setEventId(eventSelect.getSelectedIndex());
setCourseList(DataEntry.state.getCurrentEvent().getCourses());
courseSelect.setSelectedIndex(0);
}
else if (cmd.startsWith("course"))
{
DataEntry.state.setCurrentCourse((Integer)o);
Messenger.sendEvent(MT.COURSE_CHANGED, null);
groupSelect.setSelectedIndex(groupSelect.getSelectedIndex());
}
else if (cmd.startsWith("group"))
{
DataEntry.state.setCurrentRunGroup((Integer)o);
Messenger.sendEvent(MT.RUNGROUP_CHANGED, null);
}
}
else if (cmd.endsWith("Print"))
{
if (cmd.startsWith("results"))
BrowserControl.printGroupResults(DataEntry.state, new int[] {DataEntry.state.getCurrentRunGroup()});
}
}
示例11: actionPerformed
import javax.swing.JComboBox; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
final JComboBox comboBox = (JComboBox)e.getSource();
Object selectedItem = comboBox.getSelectedItem();
if (selectedItem == NEW_ITEM) {
performingNewItemAction = true;
try {
comboBox.setPopupVisible(false);
dataModel.newItemActionPerformed();
} finally {
performingNewItemAction = false;
}
setPreviousNonSpecialItem(comboBox);
// we (or maybe the client) have just selected an item inside an actionPerformed event,
// which will not send another actionPerformed event for the new item.
// We need to make sure all listeners get an event for the new item,
// thus...
final Object newSelectedItem = comboBox.getSelectedItem();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
comboBox.setSelectedItem(newSelectedItem);
}
});
}
}
示例12: 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();
}
示例13: updateColors
import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
* If the color in the <code>JComboBox</code> was already selected in
* another <code>JComboBox</code> it sets a new color in it.
*
* @param colorBox
*/
public void updateColors(JComboBox colorBox) {
List<JComboBox> colorBoxes = getColorBoxes();
String newColor = (String) colorBox.getSelectedItem();
for (JComboBox other : colorBoxes) {
if (other != colorBox && ((String) other.getSelectedItem()).equals(newColor)) {
other.setSelectedItem(getAvailableColor());
}
}
}
示例14: askFont
import javax.swing.JComboBox; //导入方法依赖的package包/类
/** Asks the user to choose a font; returns "" if the user cancels the request. */
public synchronized static String askFont() {
if (allFonts == null) allFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
JComboBox jcombo = new OurCombobox(allFonts);
Object ans = show("Font", JOptionPane.INFORMATION_MESSAGE,
new Object[] {"Please choose the new font:", jcombo}, new Object[] {"Ok", "Cancel"}, "Cancel"
);
Object value = jcombo.getSelectedItem();
if (ans=="Ok" && (value instanceof String)) return (String)value; else return "";
}
示例15: actionPerformed
import javax.swing.JComboBox; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox)e.getSource();
GraphLayout gl = (GraphLayout)cb.getSelectedItem();
gl.setGraph(wkPreview.getGraph());
wkPreview.setLayout(gl);
wkPreview.doGraphLayout();
}