List of usage examples for javax.swing JList getSelectedValue
@BeanProperty(bound = false)
public E getSelectedValue()
From source file:Main.java
public void valueChanged(ListSelectionEvent evt) { JList source = (JList) evt.getSource(); Font font = (Font) source.getSelectedValue(); label.setFont(font);/*from w ww . j a v a2 s . c om*/ }
From source file:Main.java
@Override protected Transferable createTransferable(JComponent source) { JList<String> sourceList = (JList<String>) source; String data = sourceList.getSelectedValue(); Transferable t = new StringSelection(data); return t;//from w w w .j a v a 2s . c o m }
From source file:com.konifar.material_icon_generator.FilterComboBox.java
private void initListener() { final JTextField textfield = (JTextField) this.getEditor().getEditorComponent(); textfield.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent event) { switch (event.getKeyCode()) { case KeyEvent.VK_ENTER: case KeyEvent.VK_ESCAPE: requestFocus(false);//w ww . jav a 2 s . c o m break; case KeyEvent.VK_UP: case KeyEvent.VK_DOWN: break; default: SwingUtilities.invokeLater(new Runnable() { public void run() { filter(textfield.getText()); } }); } } }); getAccessibleContext().addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (AccessibleContext.ACCESSIBLE_STATE_PROPERTY.equals(event.getPropertyName()) && AccessibleState.FOCUSED.equals(event.getNewValue()) && getAccessibleContext().getAccessibleChild(0) instanceof ComboPopup) { ComboPopup popup = (ComboPopup) getAccessibleContext().getAccessibleChild(0); JList list = popup.getList(); if (list.getSelectedValue() != null) { setSelectedItem(String.valueOf(list.getSelectedValue())); } } } }); }
From source file:Main.java
@Override protected void exportDone(JComponent source, Transferable data, int action) { @SuppressWarnings("unchecked") JList<String> sourceList = (JList<String>) source; String movedItem = sourceList.getSelectedValue(); if (action == TransferHandler.MOVE) { DefaultListModel<String> listModel = (DefaultListModel<String>) sourceList.getModel(); listModel.removeElement(movedItem); }//w w w . ja v a 2 s . c o m }
From source file:kenh.xscript.elements.Debug.java
private void list(JList c) { if (result == null) return;/*from w ww . ja v a2 s. c om*/ if (StringUtils.isBlank(c.getSelectedValue().toString())) return; if (this.getEnvironment() != null) { String context = ""; try { Object obj = this.getEnvironment().getVariable(c.getSelectedValue().toString()); if (obj != null) { context = c.getSelectedValue().toString() + LINE_SEP + LINE_SEP; context += "-- Class: " + obj.getClass().getCanonicalName() + LINE_SEP; context += LINE_SEP; context += "-- Fields: " + LINE_SEP; Field[] fields = obj.getClass().getFields(); for (Field field : fields) { int i = field.getModifiers(); String retval = Modifier.toString(i); if (StringUtils.contains(retval, "public")) { context += "\t" + field.getName() + " - " + retval + LINE_SEP; } } context += LINE_SEP; context += "-- Method: " + LINE_SEP; java.lang.reflect.Method[] methods = obj.getClass().getMethods(); for (java.lang.reflect.Method method : methods) { int i = method.getModifiers(); String retval = Modifier.toString(i); if (StringUtils.contains(retval, "public")) { Class[] pcs = method.getParameterTypes(); StringBuffer sb = new StringBuffer(); for (Class c_ : pcs) { String s = c_.getSimpleName(); sb.append(s + ", "); } String p = StringUtils.trimToEmpty(StringUtils.substringBeforeLast(sb.toString(), ",")); context += "\t" + method.getName() + "(" + p + ") - " + retval + LINE_SEP; } } } else { context = "<null>"; } } catch (Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); context = sw.toString(); } result.setText(context); } else { result.setText(c.getSelectedValue().toString()); } result.setCaretPosition(0); c.requestFocus(); }
From source file:hr.fer.zemris.vhdllab.applets.view.compilation.CompilationErrorsView.java
@Override protected JComponent createControl() { model = new DefaultListModel(); final JList listContent = new JList(model); listContent.setFixedCellHeight(15);/* w w w.ja v a 2 s.c o m*/ listContent.addMouseListener(new MouseClickAdapter() { @Override protected void onDoubleClick(MouseEvent e) { String selectedValue = (String) listContent.getSelectedValue(); highlightError(selectedValue); } }); simulationManager.addListener(this); return new JScrollPane(listContent); }
From source file:SplitPaneTest.java
public SplitPaneFrame() { setTitle("SplitPaneTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // set up components for planet names, images, descriptions final JList planetList = new JList(planets); final JLabel planetImage = new JLabel(); final JTextArea planetDescription = new JTextArea(); planetList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { Planet value = (Planet) planetList.getSelectedValue(); // update image and description planetImage.setIcon(value.getImage()); planetDescription.setText(value.getDescription()); }// w w w . j a va2 s. c om }); // set up split panes JSplitPane innerPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, planetList, planetImage); innerPane.setContinuousLayout(true); innerPane.setOneTouchExpandable(true); JSplitPane outerPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, innerPane, planetDescription); add(outerPane, BorderLayout.CENTER); }
From source file:ListCutPaste.java
/** * Bundle up the data for export.//w w w . jav a 2s. c o m */ protected Transferable createTransferable(JComponent c) { JList list = (JList) c; int index = list.getSelectedIndex(); String value = (String) list.getSelectedValue(); return new StringSelection(value); }
From source file:com.konifar.material_icon_generator.MaterialDesignIconGenerateDialog.java
private void initDpComboBox() { comboBoxDp.addActionListener(new ActionListener() { @Override//from w w w. java 2 s. c o m public void actionPerformed(ActionEvent event) { model.setDpAndFileName((String) comboBoxDp.getSelectedItem()); textFieldFileName.setText(model.getFileName()); showIconPreview(); } }); comboBoxDp.getAccessibleContext().addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (AccessibleContext.ACCESSIBLE_STATE_PROPERTY.equals(event.getPropertyName()) && AccessibleState.FOCUSED.equals(event.getNewValue()) && comboBoxDp.getAccessibleContext().getAccessibleChild(0) instanceof ComboPopup) { ComboPopup popup = (ComboPopup) comboBoxDp.getAccessibleContext().getAccessibleChild(0); JList list = popup.getList(); comboBoxDp.setSelectedItem(String.valueOf(list.getSelectedValue())); } } }); }
From source file:latexstudio.editor.DbxFileActions.java
/** * Shows a .tex files list from user's dropbox and opens the selected one * * @return List, that contatins user's .tex files from his dropbox; can be * empty/*from w w w . j a va 2 s . c o m*/ */ public void openFromDropbox(DropboxRevisionsTopComponent drtc, RevisionDisplayTopComponent revtc) { List<DbxEntryDto> dbxEntries = getDbxTexEntries(DbxUtil.getDbxClient()); if (!dbxEntries.isEmpty()) { JList<DbxEntryDto> list = new JList(dbxEntries.toArray()); list.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION); int option = JOptionPane.showConfirmDialog(null, list, "Open file from Dropbox", JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.OK_OPTION && !list.isSelectionEmpty()) { DbxEntryDto entry = list.getSelectedValue(); String localPath = ApplicationUtils.getAppDirectory() + File.separator + entry.getName(); File outputFile = DbxUtil.downloadRemoteFile(entry, localPath); revtc.close(); drtc.updateRevisionsList(entry.getPath()); drtc.open(); drtc.requestActive(); String content = FileService.readFromFile(outputFile.getAbsolutePath()); etc.setEditorContent(content); etc.setCurrentFile(outputFile); etc.setDbxState(new DbxState(entry.getPath(), entry.getRevision())); etc.setModified(false); etc.setPreviewDisplayed(false); } } else { JOptionPane.showMessageDialog(etc, "No .tex files found!", "Error", JOptionPane.ERROR_MESSAGE); } }