⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e759. adding and removing an item in a jcombobox component.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
There is no method for replacing an item. To replace an item, first remove the item and then insert the new one. 
    // Create a read-only combobox; the combobox is read-only
    // in that it does not allow the user to type in a new item.
    // The combobox still allows programmatic changes to its items.
    String[] items = {"item1", "item2"};
    JComboBox cb = new JComboBox(items);
    
    // Add an item to the start of the list
    cb.insertItemAt("item0", 0);
    
    // Add an item after the first item
    cb.insertItemAt("item0.5", 1);
    
    // Add an item to the end of the list
    cb.addItem("item3");
    
    // Remove first item
    cb.removeItemAt(0);
    
    // Remove the last item
    cb.removeItemAt(cb.getItemCount()-1);
    
    // Remove all items
    cb.removeAllItems();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -