Returns the currently selected Swing combobox value. - Java Swing

Java examples for Swing:JComboBox

Description

Returns the currently selected Swing combobox value.

Demo Code


//package com.java2s;

import javax.swing.JComboBox;

public class Main {
    /**//from w w  w .  j a va  2  s.  co m
     * Returns the currently selected combobox value.  If there
     * is no value, it return the empty string.
     */
    public static String getComboBoxValue(JComboBox comboBox) {
        if (comboBox.getSelectedItem() != null) {
            return comboBox.getSelectedItem().toString();
        } else {
            return "";
        }
    }
}

Related Tutorials