private boolean ensureSelectionExists() { if (myList.getSelectedIndex() < 0 || myList.getSelectedIndex() >= myList.getModel().getSize()) { if (myList.getModel().getSize() >= 0) { myList.setSelectedIndex(0); return false; } } return true; }
/** * Create the thumbnail image * * @return */ public ImageIcon getThumbnail() { String legendName = names[lst.getSelectedIndex()]; if (legendName.equals(UniqueSymbolPoint.NAME)) { return createImageIcon("thumbnail_unique_point.png"); } else if (legendName.equals(UniqueSymbolLine.NAME)) { return createImageIcon("thumbnail_unique_line.png"); } else if (legendName.equals(UniqueSymbolArea.NAME)) { return createImageIcon("thumbnail_unique_area.png"); } else if (legendName.equals(ProportionalPoint.NAME)) { return createImageIcon("thumbnail_proportionnal_point.png"); } else if (legendName.equals(ProportionalLine.NAME)) { return createImageIcon("thumbnail_proportionnal_line.png"); } else if (legendName.equals(RecodedPoint.NAME)) { return createImageIcon("thumbnail_recoded_point.png"); } else if (legendName.equals(RecodedLine.NAME)) { return createImageIcon("thumbnail_recoded_line.png"); } else if (legendName.equals(RecodedArea.NAME)) { return createImageIcon("thumbnail_recoded_area.png"); } else if (legendName.equals(CategorizedPoint.NAME)) { return createImageIcon("thumbnail_interval_point.png"); } else if (legendName.equals(CategorizedLine.NAME)) { return createImageIcon("thumbnail_interval_line.png"); } else if (legendName.equals(CategorizedArea.NAME)) { return createImageIcon("thumbnail_interval_area.png"); } else { return createImageIcon("thumbnail_not_found.png"); } }
public SplitPaneDemo() { // Create the list of images and put it in a scroll pane. list = new JList(imageNames); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0); list.addListSelectionListener(this); JScrollPane listScrollPane = new JScrollPane(list); picture = new JLabel(); picture.setFont(picture.getFont().deriveFont(Font.ITALIC)); picture.setHorizontalAlignment(JLabel.CENTER); JScrollPane pictureScrollPane = new JScrollPane(picture); // Create a split pane with the two scroll panes in it. splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listScrollPane, pictureScrollPane); splitPane.setOneTouchExpandable(true); splitPane.setDividerLocation(150); // Provide minimum sizes for the two components in the split pane. Dimension minimumSize = new Dimension(100, 50); listScrollPane.setMinimumSize(minimumSize); pictureScrollPane.setMinimumSize(minimumSize); // Provide a preferred size for the split pane. splitPane.setPreferredSize(new Dimension(400, 200)); updateLabel(imageNames[list.getSelectedIndex()]); }
/** Listener to handle service list selection changes */ public void valueChanged(ListSelectionEvent e) { if (service_list.getSelectedIndex() == -1) { remove_service_button.setEnabled(false); } else { remove_service_button.setEnabled(true); } }
private void updateButtons() { int index = list.getSelectedIndex(); remove.setEnabled(index != -1 && listModel.getSize() != 0); moveUp.setEnabled(index > 0); moveDown.setEnabled(index != -1 && index != listModel.getSize() - 1); edit.setEnabled(index != -1); }
// Listener method for list selection changes. public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting() == false) { if (list.getSelectedIndex() == -1) { // No selection: disable delete, up, and down buttons. deleteButton.setEnabled(false); upButton.setEnabled(false); downButton.setEnabled(false); nameField.setText(""); } else if (list.getSelectedIndices().length > 1) { // Multiple selection: disable up and down buttons. deleteButton.setEnabled(true); upButton.setEnabled(false); downButton.setEnabled(false); } else { // Single selection: permit all operations. deleteButton.setEnabled(true); upButton.setEnabled(true); downButton.setEnabled(true); nameField.setText(list.getSelectedValue().toString()); } } }
/** * Implements <code>ApplicationWindow.show</code> method. * * @param isVisible specifies whether the frame is to be visible or not. */ @Override public void setVisible(boolean isVisible) { if (isVisible && configList.getSelectedIndex() < 0) { this.configList.setSelectedIndex(0); } super.setVisible(isVisible); }
String getInstanceName(int i) { if (i < 0) i = instanceList.getSelectedIndex(); JmolInstance instance = (JmolInstance) instanceList.getModel() .getElementAt(i); return (instance == null ? "" : instance.name); }
@Override public String validateInput() { if (lst.getSelectedIndex() == -1) { return UIFactory.getI18n().tr("You must select a legend."); } return null; }
private void removeSdk() { final Sdk currentSdk = getSelectedSdk(); if (currentSdk != null) { final Sdk sdk = myProjectSdksModel.findSdk(currentSdk); final PySdkService sdkService = PySdkService.getInstance(); sdkService.removeSdk(currentSdk); DumbService.allowStartingDumbModeInside( DumbModePermission.MAY_START_MODAL, () -> SdkConfigurationUtil.removeSdk(sdk)); myProjectSdksModel.removeSdk(sdk); myProjectSdksModel.removeSdk(currentSdk); if (myModificators.containsKey(currentSdk)) { SdkModificator modificator = myModificators.get(currentSdk); myModifiedModificators.remove(modificator); myModificators.remove(currentSdk); } refreshSdkList(); mySdkListChanged = true; // TODO select initially selected SDK if (mySdkList.getSelectedIndex() < 0) { mySdkList.setSelectedIndex(0); } } }
private void moveUp() { int index = nodeList.getSelectedIndex(); index--; if (index < 0) { index = nodeList.getModel().getSize() - 1; } nodeList.setSelectedIndex(index); }
private void moveDown() { int index = nodeList.getSelectedIndex(); index++; if (index >= nodeList.getModel().getSize()) { index = 0; } nodeList.setSelectedIndex(index); }
private void removeSelectedConfiguration() { int oldSelection = myList.getSelectedIndex(); myModel.removeElement(mySelection); int size = myList.getModel().getSize(); int newSelection = oldSelection < size ? oldSelection : size - 1; if (newSelection >= 0 && newSelection < size) { myList.setSelectedIndex(newSelection); } }
private void exportSelectedCharacters() { if (herolabsCharacterList.getSelectedIndex() >= 0) { Character c = (Character) herolabsCharacterList .getModel() .getElementAt(herolabsCharacterList.getSelectedIndex()); Config.ConfigEntry ce = config.get(c.getName()); if (ce != null && ce.isOk()) { exportCharacters(); } else { JOptionPane.showMessageDialog( panel, "The character you selected hasn't been configured yet. Please configure " + "and try again.", "Export Warning", JOptionPane.WARNING_MESSAGE); } } }
/** adds a found scan to a seleceted lost package */ private void buttonSetFoundActionPerformed(ActionEvent event) { int index = jListPackages.getSelectedIndex(); if (index >= 0) { Package p = this.packages.get(index); if (p.lastScan().event == ScanEvents.lost) { p.scan(ScanEvents.found, this.user); this.packages.remove(p); this.jListPackages.setListData(new Vector(this.packages)); jListScans.setListData(new Vector()); } } }
public void onKeyPressed(KeyEvent e) { int selectedIndex = list.getSelectedIndex(); int newIndex = selectedIndex; int rowsOnScreen = scroll.getHeight() / list.getFixedCellHeight(); switch (e.getKeyCode()) { case KeyEvent.VK_UP: case KeyEvent.VK_KP_UP: if (!e.isAltDown()) { newIndex--; } break; case KeyEvent.VK_DOWN: case KeyEvent.VK_KP_DOWN: if (!e.isAltDown()) { newIndex++; } break; case KeyEvent.VK_PAGE_UP: newIndex -= rowsOnScreen; break; case KeyEvent.VK_PAGE_DOWN: newIndex += rowsOnScreen; break; case KeyEvent.VK_ENTER: if ((e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) > 0) { model.suggest(field.getText().trim()); } else if ((e.getModifiersEx() & KeyEvent.SHIFT_DOWN_MASK) > 0) { model.popOut(field.getText().trim()); } else { translateSelected(); } break; } // check, whether index was changed if (newIndex == selectedIndex) { return; } int size = list.getModel().getSize(); if (newIndex < 0) { newIndex = 0; } if (newIndex >= size) { newIndex = size - 1; } setSelectedIndex(newIndex); setSearchTextWithoutNavigating(getSelectedIndexText()); }
private void updatePreview() { String family = familyField.getText(); int size; try { size = Integer.parseInt(sizeField.getText()); } catch (Exception e) { size = 12; } int style = styleList.getSelectedIndex(); preview.setFont(new Font(family, style, size)); }
// This method is required by ListSelectionListener. public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting() == false) { if (list.getSelectedIndex() == -1) { // No selection, disable search button. // searchButton.setEnabled(false); } else { // Selection, enable the search button. // searchButton.setEnabled(true); } } }
private void suggestCompletion(final boolean selectReplacedText, final boolean isExplicitCall) { if (isExplicitCall) { myAutopopup = true; } if (!getField().isFocusOwner()) return; final CompletionResult result = new CompletionResult(); if (myList != null && myCurrentCompletion != null) { int index = myList.getSelectedIndex(); if (index >= 0 && index < myList.getModel().getSize()) { result.myPreselected = (LookupFile) myList.getSelectedValue(); } } myUiUpdater.queue( new Update("textField.suggestCompletion") { public void run() { final String completionBase = getCompletionBase(); if (completionBase != null) { final LookupFile file = myFinder.find(completionBase); if (file != null && !file.isDirectory()) { // we've entered a complete path already, no need to autopopup completion again // (IDEA-78996) return; } } result.myCompletionBase = completionBase; if (result.myCompletionBase == null) return; result.myFieldText = myPathTextField.getText(); ApplicationManager.getApplication() .executeOnPooledThread( new Runnable() { public void run() { processCompletion(result); SwingUtilities.invokeLater( new Runnable() { public void run() { if (!result.myCompletionBase.equals(getCompletionBase())) return; int pos = selectCompletionRemoveText(result, selectReplacedText); showCompletionPopup(result, pos, isExplicitCall); } }); } }); } }); }
public ListDemo() { super(new BorderLayout()); listModel = new DefaultListModel(); // Create the list and put it in a scroll pane. list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0); list.addListSelectionListener(this); list.setVisibleRowCount(5); JScrollPane listScrollPane = new JScrollPane(list); JButton hireButton = new JButton(hireString); HireListener hireListener = new HireListener(hireButton); hireButton.setActionCommand(hireString); hireButton.addActionListener(hireListener); hireButton.setEnabled(false); loadButton = new JButton(loadString); loadButton.setActionCommand(loadString); loadButton.addActionListener(new loadListener()); employeeName = new JTextField(10); employeeName.addActionListener(hireListener); employeeName.getDocument().addDocumentListener(hireListener); String name; if (listModel.size() > 0) { name = listModel.getElementAt(list.getSelectedIndex()).toString(); } // Create a panel that uses BoxLayout. JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.add(loadButton); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(new JSeparator(SwingConstants.VERTICAL)); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(employeeName); buttonPane.add(hireButton); buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(listScrollPane, BorderLayout.CENTER); add(buttonPane, BorderLayout.PAGE_END); }
@Override public void init() { JPanel pane = new JPanel(); PointOnCircle point = new PointOnCircle(); JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 50, 15); Hashtable labelTable = new Hashtable(); labelTable.put(new Integer(0), new JLabel("Stop")); labelTable.put(new Integer(15), new JLabel("Slow")); labelTable.put(new Integer(50), new JLabel("Fast")); slider.setLabelTable(labelTable); slider.setPaintLabels(true); slider.addChangeListener( e -> { int speed; JSlider source = (JSlider) e.getSource(); speed = source.getValue(); point.setSpeed(speed); }); DefaultListModel<String> model = new DefaultListModel<>(); model.addElement("Right"); model.addElement("Left"); JList list = new JList(model); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0); list.addListSelectionListener( e -> { if (list.getSelectedIndex() == 0) { point.setRight(true); } else { point.setRight(false); } }); pane.add(slider); pane.add(list); add(point, BorderLayout.CENTER); add(pane, BorderLayout.NORTH); }
/** * Returns a new {@link ILegendPanel} corresponding to the legend selected in the JList, * initialized according to the local {@link LegendContext}. * * @return Panel corresponding to selected legend, initialized appropriately. */ public ILegendPanel getSelectedPanel() { String selectedLegendTypeName = names[lst.getSelectedIndex()]; ILegendPanel panel = ILegendPanelFactory.getPanelForLegendUIChooser(editor, selectedLegendTypeName); return panel; }
private void subZListBoxEintrag() { if (zielJList.getSelectedIndex() < 0) return; else zielListModel.remove(zielJList.getSelectedIndex()); if (zielListModel.getSize() > 0) zielJList.setSelectedIndex(zielListModel.getSize() - 1); }
public ListDataEventDemo() { super(new BorderLayout()); // Create and populate the list model. listModel = new DefaultListModel(); listModel.addElement("Whistler, Canada"); listModel.addElement("Jackson Hole, Wyoming"); listModel.addElement("Squaw Valley, California"); listModel.addElement("Telluride, Colorado"); listModel.addElement("Taos, New Mexico"); listModel.addElement("Snowbird, Utah"); listModel.addElement("Chamonix, France"); listModel.addElement("Banff, Canada"); listModel.addElement("Arapahoe Basin, Colorado"); listModel.addElement("Kirkwood, California"); listModel.addElement("Sun Valley, Idaho"); listModel.addListDataListener(new MyListDataListener()); // Create the list and put it in a scroll pane. list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); list.setSelectedIndex(0); list.addListSelectionListener(this); JScrollPane listScrollPane = new JScrollPane(list); // Create the list-modifying buttons. addButton = new JButton(addString); addButton.setActionCommand(addString); addButton.addActionListener(new AddButtonListener()); deleteButton = new JButton(deleteString); deleteButton.setActionCommand(deleteString); deleteButton.addActionListener(new DeleteButtonListener()); ImageIcon icon = createImageIcon("Up16"); if (icon != null) { upButton = new JButton(icon); upButton.setMargin(new Insets(0, 0, 0, 0)); } else { upButton = new JButton("Move up"); } upButton.setToolTipText("Move the currently selected list item higher."); upButton.setActionCommand(upString); upButton.addActionListener(new UpDownListener()); icon = createImageIcon("Down16"); if (icon != null) { downButton = new JButton(icon); downButton.setMargin(new Insets(0, 0, 0, 0)); } else { downButton = new JButton("Move down"); } downButton.setToolTipText("Move the currently selected list item lower."); downButton.setActionCommand(downString); downButton.addActionListener(new UpDownListener()); JPanel upDownPanel = new JPanel(new GridLayout(2, 1)); upDownPanel.add(upButton); upDownPanel.add(downButton); // Create the text field for entering new names. nameField = new JTextField(15); nameField.addActionListener(new AddButtonListener()); String name = listModel.getElementAt(list.getSelectedIndex()).toString(); nameField.setText(name); // Create a control panel, using the default FlowLayout. JPanel buttonPane = new JPanel(); buttonPane.add(nameField); buttonPane.add(addButton); buttonPane.add(deleteButton); buttonPane.add(upDownPanel); // Create the log for reporting list data events. log = new JTextArea(10, 20); JScrollPane logScrollPane = new JScrollPane(log); // Create a split pane for the log and the list. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, listScrollPane, logScrollPane); splitPane.setResizeWeight(0.5); // Put everything together. add(buttonPane, BorderLayout.PAGE_START); add(splitPane, BorderLayout.CENTER); }
public Object getSelected() { return ids[lst.getSelectedIndex()]; }
public int getSelectedIndex() { return lst.getSelectedIndex(); }
public void updateState() { actDelEntity.setEnabled(-1 != lstEntities.getSelectedIndex()); }
public void actionPerformed(ActionEvent e) { JButton source = (JButton) e.getSource(); if (source == showButton) sp.doVisualComparison(list.getSelectedIndex(), scores[list.getSelectedIndex()]); else dispose(); }
// Listens to the list public void valueChanged(ListSelectionEvent e) { JList list = (JList) e.getSource(); updateLabel(imageNames[list.getSelectedIndex()]); }
/** * Handles selected index change for the packages Jlist. Dsiplays the scan history of the selected * package in the scans JList. */ private void jListPackagesActionPertformed(ListSelectionEvent event) { int index = jListPackages.getSelectedIndex(); if (index >= 0) jListScans.setListData(new Vector(this.packages.get(index).scanHistory)); }