本文整理匯總了Java中javax.swing.DefaultListModel.set方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultListModel.set方法的具體用法?Java DefaultListModel.set怎麽用?Java DefaultListModel.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.DefaultListModel
的用法示例。
在下文中一共展示了DefaultListModel.set方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: moveUpButtonActionPerformed
import javax.swing.DefaultListModel; //導入方法依賴的package包/類
private void moveUpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveUpButtonActionPerformed
int[] indexes = displayedGroupsList.getSelectedIndices();
DefaultListModel displayedModel = (DefaultListModel) displayedGroupsList.getModel();
for (int index : indexes) {
Object down = displayedModel.get(index - 1);
Object up = displayedModel.get(index);
displayedModel.set(index, down);
displayedModel.set(index - 1, up);
}
for (int i = 0; i < indexes.length; i++) {
indexes[i]--;
}
displayedGroupsList.setSelectedIndices(indexes);
}
示例2: moveDownButtonActionPerformed
import javax.swing.DefaultListModel; //導入方法依賴的package包/類
private void moveDownButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveDownButtonActionPerformed
int[] indexes = displayedGroupsList.getSelectedIndices();
DefaultListModel displayedModel = (DefaultListModel) displayedGroupsList.getModel();
for (int index : indexes) {
Object down = displayedModel.get(index);
Object up = displayedModel.get(index + 1);
displayedModel.set(index + 1, down);
displayedModel.set(index, up);
}
for (int i = 0; i < indexes.length; i++) {
indexes[i]++;
}
displayedGroupsList.setSelectedIndices(indexes);
}
示例3: setModel
import javax.swing.DefaultListModel; //導入方法依賴的package包/類
/**
* Set the content of the model to the list.
* @param model
* @param list items that will be inserted into the model.
*/
private void setModel(DefaultListModel model, List<T> list) {
model.setSize(list.size() + 1);
model.set(0, getNewItemLabel());
for (int i = 0; i < list.size(); ++i) {
model.set(i + 1, list.get(i));
}
}
示例4: importData
import javax.swing.DefaultListModel; //導入方法依賴的package包/類
@Override public boolean importData(TransferHandler.TransferSupport info) {
if (!info.isDrop()) {
return false;
}
JList list = (JList) info.getComponent();
DefaultListModel listModel = (DefaultListModel) list.getModel();
JList.DropLocation dl = (JList.DropLocation) info.getDropLocation();
int index = dl.getIndex();
boolean insert = dl.isInsert();
// Get the string that is being dropped.
Transferable t = info.getTransferable();
String data;
try {
data = (String) t.getTransferData(DataFlavor.stringFlavor);
} catch (Exception e) {
return false;
}
// Perform the actual import.
if (insert) {
listModel.add(index, data);
} else {
listModel.set(index, data);
}
return true;
}