javax.swing.JList#setSelectedIndices ( )源码实例Demo

下面列出了javax.swing.JList#setSelectedIndices ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: SuitePropertiesTest.java
public void testRemoveAllSubModules() throws Exception {
    SuiteProject suite1 = generateSuite("suite1");
    TestBase.generateSuiteComponent(suite1, "module1a");
    TestBase.generateSuiteComponent(suite1, "module1b");
    SuiteProperties suite1Props = getSuiteProperties(suite1);
    
    SuiteSubModulesListModel model = suite1Props.getModulesListModel();
    assertNotNull(model);
    
    // simulate removing all items from the list
    JList moduleList = new JList(model);
    moduleList.setSelectedIndices(new int[] {0, model.getSize() - 1});
    model.removeModules(Arrays.asList(moduleList.getSelectedValues()));
    assertEquals("no subModule should be left", 0, model.getSize());
    
    saveProperties(suite1Props);
    
    SubprojectProvider spp = getSubProjectProvider(suite1);
    assertEquals("no module should be left", 0, spp.getSubprojects().size());
}
 
源代码2 项目: iBioSim   文件: Utility.java
/**
 * Returns a list of all the objects in the given JList.
 */
public static String[] getList(Object[] size, JList objects) {
	String[] list;
	if (size.length == 0) {
		list = new String[0];
	}
	else {
		int[] select = new int[size.length];
		for (int i = 0; i < size.length; i++) {
			select[i] = i;
		}
		objects.setSelectedIndices(select);
		size = objects.getSelectedValues();
		list = new String[size.length];
		for (int i = 0; i < size.length; i++) {
			list[i] = (String) size[i];
		}
	}
	return list;
}
 
源代码3 项目: zap-extensions   文件: WebSocketUiHelper.java
public void setSelectedOpcodes(List<String> opcodes) {
    JList<String> opcodesList = getOpcodeList();
    if (opcodes == null || opcodes.contains(SELECT_ALL_OPCODES)) {
        opcodesList.setSelectedIndex(0);
    } else {
        int j = 0;
        int[] selectedIndices = new int[opcodes.size()];
        ListModel<String> model = opcodesList.getModel();
        for (int i = 0; i < model.getSize(); i++) {
            String item = model.getElementAt(i);
            if (opcodes.contains(item)) {
                selectedIndices[j++] = i;
            }
        }
        opcodesList.setSelectedIndices(selectedIndices);
    }
}
 
源代码4 项目: zap-extensions   文件: WebSocketUiHelper.java
public void setSelectedChannelIds(List<Integer> channelIds) {
    JList<WebSocketChannelDTO> channelsList = getChannelsList();
    if (channelIds == null || channelIds.contains(-1)) {
        channelsList.setSelectedIndex(0);
    } else {
        int[] selectedIndices = new int[channelIds.size()];
        ListModel<WebSocketChannelDTO> model = channelsList.getModel();
        for (int i = 0, j = 0; i < model.getSize(); i++) {
            WebSocketChannelDTO channel = model.getElementAt(i);
            if (channelIds.contains(channel.id)) {
                selectedIndices[j++] = i;
            }
        }
        channelsList.setSelectedIndices(selectedIndices);
    }
}
 
源代码5 项目: snap-desktop   文件: OperatorUIUtils.java
public static void setSelectedListIndices(final JList list, final List<Integer> indices) {
    final int[] selIndex = new int[indices.size()];
    for (int i = 0; i < indices.size(); ++i) {
        selIndex[i] = indices.get(i);
    }
    list.setSelectedIndices(selIndex);
}
 
源代码6 项目: CQL   文件: UniqueKeyUI.java
/**
 * Generates the options/controls to prompt the user for unique key details
 *
 * @return
 */
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<Option> getOptions() {
	LinkedList<Option> opts = new LinkedList<>();

	opts.add(new Option("Unique key name:", _keyNameField = JUtils.textField("")));

	if (_uniqueKey != null) {
		_keyNameField.setText(_uniqueKey.getKeyName());
	}

	// Add the attributes box (only if there are attributes)
	EntityAttribute[] atts = _entity.getEntityAttributes().toArray(new EntityAttribute[0]);

	_attListField = new JList(atts);

	if (atts.length > 0) {
		opts.add(new Option("Unique key attributes:", JUtils.fixHeight(new JScrollPane(_attListField))));
	}

	// Add the outgoing edges box (only if there are outgoing edges)
	UniqueIndexable[] edges = _entity.getIndexableEdges().toArray(new UniqueIndexable[0]);

	_edgeListField = new JList(edges);

	if (edges.length > 0) {
		opts.add(new Option("Unique key edges:", JUtils.fixHeight(new JScrollPane(_edgeListField))));
	}

	if (_uniqueKey != null) {
		Set<UniqueIndexable> elems = _uniqueKey.getElements();
		ArrayList<Integer> setAtt = new ArrayList<>();
		ArrayList<Integer> setEdges = new ArrayList<>();

		for (int i = 0; i < atts.length; i++) {
			if (elems.contains(atts[i])) {
				setAtt.add(i);
			}
		}

		for (int i = 0; i < edges.length; i++) {
			if (elems.contains(edges[i])) {
				setEdges.add(i);
			}
		}

		int[] setA = new int[setAtt.size()];
		int[] setE = new int[setEdges.size()];

		for (int i = 0; i < setAtt.size(); i++) {
			setA[i] = setAtt.get(i);
		}

		for (int i = 0; i < setEdges.size(); i++) {
			setE[i] = setEdges.get(i);
		}

		_attListField.setSelectedIndices(setA);
		_edgeListField.setSelectedIndices(setE);
	}

	return opts;
}
 
源代码7 项目: pumpernickel   文件: ShowcaseIconDemo.java
@Override
public void actionPerformed(ActionEvent e) {
	JList<?> list = (JList<?>) e.getSource();
	list.setSelectedIndices(new int[] {});
}
 
public PerformanceVectorViewer(final PerformanceVector performanceVector, final IOContainer container) {
	setLayout(new BorderLayout());

	// all criteria
	final CardLayout cardLayout = new CardLayout();
	final JPanel mainPanel = new JPanel(cardLayout);
	add(mainPanel, BorderLayout.CENTER);
	List<String> criteriaNameList = new LinkedList<>();
	for (int i = 0; i < performanceVector.getSize(); i++) {
		PerformanceCriterion criterion = performanceVector.getCriterion(i);
		criteriaNameList.add(criterion.getName());
		JPanel component = ResultDisplayTools.createVisualizationComponent(criterion, container,
				"Performance Criterion", false);
		JScrollPane criterionPane = new ExtendedJScrollPane(component);
		criterionPane.setBorder(null);
		criterionPane.setBackground(Colors.WHITE);
		mainPanel.add(criterionPane, criterion.getName());
	}
	if (criteriaNameList.isEmpty()) {
		remove(mainPanel);
		add(new ResourceLabel("result_view.no_criterions"));
		return;
	}
	String[] criteriaNames = new String[criteriaNameList.size()];
	criteriaNameList.toArray(criteriaNames);

	// selection list
	final JList<String> criteriaList = new MenuShortcutJList<String>(criteriaNames, false) {

		private static final long serialVersionUID = 3031125186920370793L;

		@Override
		public Dimension getPreferredSize() {
			Dimension dim = super.getPreferredSize();
			dim.width = Math.max(150, dim.width);
			return dim;
		}
	};
	criteriaList.setCellRenderer(new CriterionListCellRenderer());
	criteriaList.setOpaque(false);

	criteriaList.setBorder(BorderFactory.createTitledBorder("Criterion"));
	criteriaList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

	criteriaList.addListSelectionListener(new ListSelectionListener() {

		@Override
		public void valueChanged(ListSelectionEvent e) {
			String selected = criteriaList.getSelectedValue();
			cardLayout.show(mainPanel, selected);
		}
	});

	JScrollPane listScrollPane = new ExtendedJScrollPane(criteriaList);
	listScrollPane.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 2));
	add(listScrollPane, BorderLayout.WEST);

	// select first criterion
	criteriaList.setSelectedIndices(new int[] { 0 });
}
 
源代码9 项目: osp   文件: DataTable.java
void setColumns(String[] names, String[] selected) {
  displayedNames = new String[names.length];
  realNames.clear();
	for (int i=0; i<names.length; i++) {
    String s = TeXParser.removeSubscripting(names[i]);
		// add white space for better look
		displayedNames[i] = "   "+s+" "; //$NON-NLS-1$ //$NON-NLS-2$
		realNames.put(displayedNames[i], names[i]);
  	if (selected!=null) {
   	for (int j=0; j<selected.length; j++) {
   		if (selected[j]!=null && selected[j].equals(names[i])) {
   			selected[j] = displayedNames[i];
   		}
   	}
  	}
	}
  prevPatterns.clear();
  for(String name : names) {
    prevPatterns.put(name, getFormatPattern(name));
  }
  // create column list and add to scroller
  columnList = new JList(displayedNames);
  columnList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
  columnList.setVisibleRowCount(-1);
  columnList.addListSelectionListener(new ListSelectionListener() {
  	public void valueChanged(ListSelectionEvent e) {
  		showNumberFormatAndSample(columnList.getSelectedIndices());
  	}
  });
  columnScroller.setViewportView(columnList);
  pack();
  int[] indices = null;
  if (selected!=null) {
    // select requested names
    indices = new int[selected.length];
    for (int j=0; j<indices.length; j++) {
    	inner:
     for (int i = 0; i< displayedNames.length; i++) {
     	if (displayedNames[i].equals(selected[j])) {
     		indices[j] = i;
     		break inner;
     	}
     }
    }
  	columnList.setSelectedIndices(indices);
  }
  else
    showNumberFormatAndSample(indices);
}