How to retrieve index of combobox from a string?

1

I have the String for a combobox item, but when the user clicks the table, the combobox must automatically select the category of that certain item. However, I came across that there is no getIndex function as I put below. How can I retrieve the index from this string?

private void TabelaMouseClicked(java.awt.event.MouseEvent evt) {                                    
    // Click na tabela para selecionar produto:
    if (Tabela.getSelectedRow() != -1){

        txt_descricao.setText(Tabela.getValueAt(Tabela.getSelectedRow(), 1).toString());
        cb_marca.getIndexOf("teste");

    }
} 
    
asked by anonymous 12.10.2017 / 21:12

1 answer

5

How are you using DefaultComboBoxModel , the method for retrieving the index of an item if it exists in the combo is through the getIndexOf ":

((DefaultComboBoxModel)seucombo.getModel()).getIndexOf(anObject);

Just pointing out that it returns -1 if the object is not found among the ComboBox items.

    
12.10.2017 / 21:22