当前位置: 首页>>代码示例>>Java>>正文


Java DefaultListModel.add方法代码示例

本文整理汇总了Java中javax.swing.DefaultListModel.add方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultListModel.add方法的具体用法?Java DefaultListModel.add怎么用?Java DefaultListModel.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.DefaultListModel的用法示例。


在下文中一共展示了DefaultListModel.add方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: browse

import javax.swing.DefaultListModel; //导入方法依赖的package包/类
private void browse(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browse
    try {
        final Collection<Integer> added = new ArrayList<>();
        final List<? extends String> paths = browseCall.call();
        if (paths != null) {
            final DefaultListModel<URI> lm = (DefaultListModel<URI>) sources.getModel();
            final Set<URI> contained = new HashSet<>(Collections.list(lm.elements()));
            int index = sources.getSelectedIndex();
            index = index < 0 ? lm.getSize() : index + 1;
            for (String path : paths) {
                for (URI uri : convertor.call(path)) {
                    if (!contained.contains(uri)) {
                        lm.add(index, uri);
                        added.add(index);
                        index++;
                    }
                }
            }
        }
        select(added);
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:SelectRootsPanel.java

示例2: addJarFiles

import javax.swing.DefaultListModel; //导入方法依赖的package包/类
public static int[] addJarFiles( DefaultListModel listModel, int[] indices, String filePaths[], File base, 
        String[] variables, Callback callback) {
    int lastIndex = indices == null || indices.length == 0 ? listModel.getSize() - 1 : indices[indices.length - 1];
    int[] indexes = new int[filePaths.length];
    for( int i = 0, delta = 0; i+delta < filePaths.length; ) {            
        int current = lastIndex + 1 + i;
        ClassPathSupport.Item item = ClassPathSupport.Item.create( filePaths[i], base, null, variables != null ? variables[i] : null);
        if (callback != null) {
            callback.initItem(item);
        }
        if ( !listModel.contains( item ) ) {
            listModel.add( current, item );
            indexes[delta + i] = listModel.indexOf( item );
            i++;
        }
        else {
            indexes[i + delta] = listModel.indexOf( item );
            delta++;
        }            
    }
    return indexes;

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:ClassPathUiSupport.java

示例3: addArtifacts

import javax.swing.DefaultListModel; //导入方法依赖的package包/类
public static int[] addArtifacts( DefaultListModel listModel, int[] indices, AntArtifactItem artifactItems[],
        Callback callback) {
    int lastIndex = indices == null || indices.length == 0 ? listModel.getSize() - 1 : indices[indices.length - 1];
    int[] indexes = new int[artifactItems.length];
    for( int i = 0; i < artifactItems.length; i++ ) {
        int current = lastIndex + 1 + i;
        ClassPathSupport.Item item = ClassPathSupport.Item.create( artifactItems[i].getArtifact(), artifactItems[i].getArtifactURI(), null) ;
        if (callback != null) {
            callback.initItem(item);
        }
        if ( !listModel.contains( item ) ) {
            listModel.add( current, item );
        }            
        indexes[i] = listModel.indexOf( item );
    }
    return indexes;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:ClassPathUiSupport.java

示例4: addElement

import javax.swing.DefaultListModel; //导入方法依赖的package包/类
/**
 * Adds the element sorted to the model
 *
 * @param model
 * @param element
 * @return index of the new element
 */
private int addElement(DefaultListModel<String> model, String element) {

	if (model.isEmpty()) {
		model.addElement(element);
		return 0;
	} else {
		for (int j = 0; j < model.getSize(); j++) {

			int compareValue = String.CASE_INSENSITIVE_ORDER.compare(model.getElementAt(j).toString(), element);
			if (compareValue > 0) {
				model.add(j, element);
				return j;
			}
			if (j == model.getSize() - 1) {
				model.add(j + 1, element);
				return j + 1;
			}
		}
	}
	// sth went wrong
	return -1;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:30,代码来源:ConfigurableUserAccessDialog.java

示例5: importData

import javax.swing.DefaultListModel; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public boolean importData(JComponent target, Transferable data) {
    JList<TradeRouteStop> stl = TradeRouteInputPanel.this.stopList;
    if (canImport(target, data.getTransferDataFlavors())
        && target == stl
        && data instanceof StopListTransferable) {
        List<TradeRouteStop> stops
            = ((StopListTransferable)data).getStops();
        DefaultListModel<TradeRouteStop> model
            = new DefaultListModel<>();
        int index = stl.getMaxSelectionIndex();
        for (TradeRouteStop stop : stops) {
            if (index < 0) {
                model.addElement(stop);
            } else {
                index++;
                model.add(index, stop);
            }
        }
        stl.setModel(model);
        return true;
    }
    return false;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:28,代码来源:TradeRouteInputPanel.java

示例6: reorderProjects

import javax.swing.DefaultListModel; //导入方法依赖的package包/类
private Boolean reorderProjects(TransferHandler.TransferSupport support) {
    JList list = (JList) support.getComponent();
    try {
        int[] selectedIndices = (int[]) support.getTransferable().getTransferData(INDICES);
        DefaultListModel model = (DefaultListModel) list.getModel();
        JList.DropLocation dl = (JList.DropLocation) support.getDropLocation();
        if (dl.getIndex() != -1) {
            for (int selectedIndex : selectedIndices) {
                Object value = model.get(selectedIndex);
                model.removeElement(value);
                model.add(dl.getIndex(), value);
            }
            return true;
        } else {
            LOG.warning("Invalid Drop Location");
        }
    } catch (UnsupportedFlavorException | IOException ex) {
        LOG.log(Level.SEVERE, ex.getMessage(), ex);
    }
    return false;
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:22,代码来源:InjectScript.java

示例7: moveUp

import javax.swing.DefaultListModel; //导入方法依赖的package包/类
private void moveUp(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveUp
    final DefaultListModel<URI> lm = (DefaultListModel<URI>) sources.getModel();
    final int[] index = sources.getSelectedIndices();
    for (int i=0; i< index.length; i++) {
        final URI toMove = lm.remove(index[i]);
        lm.add(index[i]-1, toMove);
        index[i]--;
    }
    sources.setSelectedIndices(index);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:SelectRootsPanel.java

示例8: moveDown

import javax.swing.DefaultListModel; //导入方法依赖的package包/类
private void moveDown(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveDown
    final DefaultListModel<URI> lm = (DefaultListModel<URI>) sources.getModel();
    final int[] index = sources.getSelectedIndices();
    for (int i=index.length-1; i>=0; i--) {
        final URI toMove = lm.remove(index[i]);
        lm.add(index[i]+1, toMove);
        index[i]++;
    }
    sources.setSelectedIndices(index);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:SelectRootsPanel.java

示例9: addURL

import javax.swing.DefaultListModel; //导入方法依赖的package包/类
private void addURL(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addURL
    final NotifyDescriptor.InputLine nd = new NotifyDescriptor.InputLine(
        NbBundle.getMessage(SelectRootsPanel.class,"TXT_RemoteJavadoc"),
        NbBundle.getMessage(SelectRootsPanel.class,"TXT_RemoteJavadoc_Title"),
        NotifyDescriptor.OK_CANCEL_OPTION,
        NotifyDescriptor.PLAIN_MESSAGE);
    if (DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.OK_OPTION) {
        final String inputText = nd.getInputText();
        final DefaultListModel<URI> lm = (DefaultListModel<URI>) sources.getModel();
        final Set<URI> contained = new HashSet<>(Collections.list(lm.elements()));
        int index = sources.getSelectedIndex();
        index = index < 0 ? lm.getSize() : index + 1;
        try {
            URI uri = new URI(inputText);
            if (!contained.contains(uri)) {
                lm.add(index, uri);
                select(Collections.<Integer>singleton(index));
                index++;
            }
        } catch (URISyntaxException ex) {
            DialogDisplayer.getDefault().notify(
                new NotifyDescriptor.Message(
                    NbBundle.getMessage(SelectRootsPanel.class, "TXT_InvalidRoot", inputText),
                    NotifyDescriptor.ERROR_MESSAGE));
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:SelectRootsPanel.java

示例10: addButtonActionPerformed

import javax.swing.DefaultListModel; //导入方法依赖的package包/类
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
    int[] indexes = availableGroupsList.getSelectedIndices();
    DefaultListModel availableModel = (DefaultListModel) availableGroupsList.getModel();
    DefaultListModel displayedModel = (DefaultListModel) displayedGroupsList.getModel();
    int at = displayedModel.getSize();
    for (int i = indexes.length - 1; i >= 0; i--) {
        Object element = availableModel.remove(indexes[i]);
        displayedModel.add(at, element);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:BreakpointNestedGroupsDialog.java

示例11: removeButtonActionPerformed

import javax.swing.DefaultListModel; //导入方法依赖的package包/类
private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
    int[] indexes = displayedGroupsList.getSelectedIndices();
    DefaultListModel availableModel = (DefaultListModel) availableGroupsList.getModel();
    DefaultListModel displayedModel = (DefaultListModel) displayedGroupsList.getModel();
    int at = availableModel.getSize();
    for (int i = indexes.length - 1; i >= 0; i--) {
        Object element = displayedModel.remove(indexes[i]);
        availableModel.add(at, element);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:BreakpointNestedGroupsDialog.java

示例12: 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;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:29,代码来源:ListTransferHandler.java

示例13: importString

import javax.swing.DefaultListModel; //导入方法依赖的package包/类
protected void importString(JComponent c, String str) {
    JList target = (JList) c;
    DefaultListModel listModel = (DefaultListModel) target.getModel();
    int index = target.getSelectedIndex();

    // Prevent the user from dropping data back on itself.
    // For example, if the user is moving items #4,#5,#6 and #7 and
    // attempts to insert the items after item #5, this would
    // be problematic when removing the original items.
    // So this is not allowed.
    if (indices != null && index >= indices[0] - 1 && index <= indices[indices.length - 1]) {
        indices = null;
        return;
    }

    int max = listModel.getSize();
    if (index < 0) {
        index = max;
    } else {
        index++;
        if (index > max) {
            index = max;
        }
    }
    addIndex = index;
    String[] values = str.split("\n");
    addCount = values.length;
    for (String value : values) {
        listModel.add(index++, value);
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:32,代码来源:ListTransferHandler.java


注:本文中的javax.swing.DefaultListModel.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。