简体   繁体   中英

Upgrade the Items of JCombobox

I want to upgrade the list items of myComboBox when I click a row in myJtabel. I did what I must do to have a good result. But when a unpgrade myComboBox I have a true as a last item and every time I have done an upgrade adds a true as item

What it does not go in my class

myUpgradeCombo :

    class myUpgradeCombo {

public static <E> void upgrade_(JComboBox<E> combo, int index)
    {
        E item = combo.getItemAt(index);
        combo.removeItemAt(index);
        combo.insertItemAt(item, 0);
        combo.setSelectedIndex(0);
    }

    public static <E> boolean upgrade(JComboBox<E> combo, E item)
    {
        for (int index=0; index<combo.getItemCount(); index++)
        {
            if (combo.getItemAt(index).toString().equals(item.toString()))
            {
                upgrade_(combo,index);

                return true;
            }
        }
         return false ;
    }
}

when myJtable Mouse pressed :

    int rec = myJtableF.getSelectedRow();
String idf = myJtableF.getValueAt(rec, 1).toString();
String format = myJtableF.getValueAt(rec, 2).toString();
String platef = myJtableF.getValueAt(rec, 3).toString(); 
this.myCombo.addItem(myUpgradeCombo.upgrade(myCombo, new FC(format,platef,idf)));

As result in myCombo :

...... MySelectedItem
.......Firstitem
.......SecondItem
.......ThirdItem
.......fourthItem
.......true
.......true

Thanks,

Well because the return value of your myUpgradeCombo.upgrade(myCombo, new FC(format,platef,idf)) is passed to this.myCombo.addItem().

So the true returned from upgrade() is added as an item to your combo box, in this line:

this.myCombo.addItem(myUpgradeCombo.upgrade(myCombo, new FC(format,platef,idf)));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM