private void update(DocumentEvent event) { String newValue = ""; try { Document doc = event.getDocument(); newValue = doc.getText(0, doc.getLength()); } catch (BadLocationException e) { Luyten.showExceptionDialog("Exception!", e); } if (newValue.length() > 0) { int index = targetList.getNextMatch(newValue, 0, Position.Bias.Forward); if (index < 0) { index = 0; } targetList.ensureIndexIsVisible(index); String matchedName = targetList.getModel().getElementAt(index).toString(); if (newValue.equalsIgnoreCase(matchedName)) { if (index != targetList.getSelectedIndex()) { SwingUtilities.invokeLater(new ListSelector(index)); } } } }
JList wordList = getWordListScroller (); int lastIndex = wordList.getModel().getSize() - 1; if (lastIndex >= 0) { wordList.ensureIndexIsVisible(lastIndex); }
private void doPrevSelect() { int newSel = this.listChoices.getSelectedIndex() - 1; if (newSel >= 0) { this.listChoices.setSelectedIndex(newSel); this.listChoices.ensureIndexIsVisible(newSel); } }
private void doPrevSelect() { int newSel = this.listChoices.getSelectedIndex() - 1; if (newSel >= 0) { this.listChoices.setSelectedIndex(newSel); this.listChoices.ensureIndexIsVisible(newSel); } }
private void doNextSelect() { int newSel = this.listChoices.getSelectedIndex() + 1; int maxSel = this.listChoices.getModel().getSize() - 1; if (newSel <= maxSel) { this.listChoices.setSelectedIndex(newSel); this.listChoices.ensureIndexIsVisible(newSel); } }
private void doNextSelect() { int newSel = this.listChoices.getSelectedIndex() + 1; int maxSel = this.listChoices.getModel().getSize() - 1; if (newSel <= maxSel) { this.listChoices.setSelectedIndex(newSel); this.listChoices.ensureIndexIsVisible(newSel); } }
private void moveDown() { int index = nodeList.getSelectedIndex(); index++; if (index >= nodeList.getModel().getSize()) { index = 0; } nodeList.setSelectedIndex(index); nodeList.ensureIndexIsVisible(index); }
private void moveUp() { int index = nodeList.getSelectedIndex(); index--; if (index < 0) { index = nodeList.getModel().getSize() - 1; } nodeList.setSelectedIndex(index); nodeList.ensureIndexIsVisible(index); }
public void actionPerformed(ActionEvent e) { int i = control.getSelectedIndex(); moveUp(i); updateList(); control.setSelectedIndex(i - 1); control.ensureIndexIsVisible(i - 1); control.repaint(); } }
public void actionPerformed(ActionEvent e) { int i = control.getSelectedIndex(); moveDown(i); updateList(); control.setSelectedIndex(i + 1); control.ensureIndexIsVisible(i + 1); control.repaint(); } }
private void reloadListModel() { functionLibraryListModel.updateFunctionLibraries(); functionLibraryList.setModel(functionLibraryListModel); functionLibraryList.setSelectedIndex(0); functionLibraryList.ensureIndexIsVisible(0); functionLibraryList.setCellRenderer(new FunctionLibraryRenderer()); repaint(); } }
final JList list = new JList(Locale.getAvailableLocales()); final JPopupMenu popup = new JPopupMenu(); popup.add(new JScrollPane(list)); popup.setFocusable(false); final JTextField field = new JTextField(20); Action down = new AbstractAction("nextElement") { @Override public void actionPerformed(ActionEvent e) { int next = Math.min(list.getSelectedIndex() + 1, list.getModel().getSize() - 1); list.setSelectedIndex(next); list.ensureIndexIsVisible(next); } }; field.getActionMap().put("nextElement", down); field.getInputMap().put( KeyStroke.getKeyStroke("DOWN"), "nextElement");
@Override public void run() { list.ensureIndexIsVisible(index); // Fix of #10787. // This is workaround for swing bug - BasicListUI doesn't ask for preferred // size of rendered list cell as a result of property selectedIndex change. // It does only on certain JList property changes (e.g. fixedCellWidth). // Maybe subclassing BasicListUI could be better fix. list.setFixedCellWidth(0); list.setFixedCellWidth(-1); } }
private void changedEvent() { if (filteredNodeListModel.getSearchString().equals(searchField.getText())) return; filteredNodeListModel.setSearchString(searchField.getText()); // Trigger a model reload. nodeList.setSelectedIndex(0); nodeList.ensureIndexIsVisible(0); nodeList.revalidate(); repaint(); } }
public void setSelectedValues(JList list, Object... values) { list.clearSelection(); for (Object value : values) { int index = getIndex(list.getModel(), value); if (index >=0) { list.addSelectionInterval(index, index); } } list.ensureIndexIsVisible(list.getSelectedIndex()); } public int getIndex(ListModel model, Object value) { if (value == null) return -1; if (model instanceof DefaultListModel) { return ((DefaultListModel) model).indexOf(value); } for (int i = 0; i < model.getSize(); i++) { if (value.equals(model.getElementAt(i))) return i; } return -1; }
public void setSelectedCategory(CategoryLabel label) { if (selectedCategory != null) selectedCategory.setSelected(false); selectedCategory = label; if (selectedCategory != null) { selectedCategory.setSelected(true); filteredNodeListModel.setCategory((String) selectedCategory.source); // Trigger a model reload. nodeList.setSelectedIndex(0); nodeList.ensureIndexIsVisible(0); nodeList.revalidate(); nodeList.repaint(); } }
this.listChoices.ensureIndexIsVisible(selectIndex);
currentlistChoices.ensureIndexIsVisible(selectIndex);
rows.ensureIndexIsVisible(rows.getModel().getSize()); rows.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); rows.setLayoutOrientation(JList.VERTICAL);
/** * Selects the next item in the list. It won't change the selection if the * currently selected item is already the last item. */ protected void selectNextPossibleValue(){ int si = list.getSelectedIndex(); if(si < list.getModel().getSize() - 1){ int nextIndex = si + 1; list.setSelectedIndex(nextIndex); list.ensureIndexIsVisible(nextIndex); } }