本文整理匯總了Java中javax.swing.JComboBox.insertItemAt方法的典型用法代碼示例。如果您正苦於以下問題:Java JComboBox.insertItemAt方法的具體用法?Java JComboBox.insertItemAt怎麽用?Java JComboBox.insertItemAt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JComboBox
的用法示例。
在下文中一共展示了JComboBox.insertItemAt方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
}
示例2: addQueryHistory
import javax.swing.JComboBox; //導入方法依賴的package包/類
/**
* Add the query to the history
*/
private void addQueryHistory(String queryString) {
JComboBox<String> query = getQueryField();
query.removeItem(queryString);
query.insertItemAt(queryString, 0);
query.setSelectedIndex(0);
while (query.getItemCount() > MAX_HISTORY) {
query.removeItemAt(MAX_HISTORY);
}
// store the history
StringBuilder sb = new StringBuilder();
for (int i = 0; i < query.getItemCount(); i++) {
if (i > 0) {
sb.append("\n");
}
sb.append(query.getItemAt(i));
}
PREFS.put("queryHistory", sb.toString());
}
示例3: showInfo
import javax.swing.JComboBox; //導入方法依賴的package包/類
/**
* Show information about a host
* @param host Host to show the information of
*/
@SuppressWarnings("unchecked")
public void showInfo(DTNHost host) {
Vector messages = new Vector<Message>(host.getMessageCollection());
Collections.sort(messages);
reset();
this.selectedHost = host;
String text = (host.isActive() ? "" : "INACTIVE ") + host + " at " +
host.getLocation();
msgChooser = new JComboBox(messages);
msgChooser.insertItemAt(messages.size() + " messages", 0);
msgChooser.setSelectedIndex(0);
msgChooser.addActionListener(this);
routingInfoButton = new JButton("routing info");
routingInfoButton.addActionListener(this);
this.add(new JLabel(text));
this.add(msgChooser);
this.add(routingInfoButton);
this.revalidate();
}