List of usage examples for javax.swing.event ListSelectionListener ListSelectionListener
ListSelectionListener
From source file:LongListTest.java
public LongListFrame() { setTitle("LongListTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); wordList = new JList(new WordListModel(3)); wordList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); wordList.setPrototypeCellValue("www"); JScrollPane scrollPane = new JScrollPane(wordList); JPanel p = new JPanel(); p.add(scrollPane);/* www.j a v a 2s .co m*/ wordList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { StringBuilder word = (StringBuilder) wordList.getSelectedValue(); setSubject(word.toString()); } }); Container contentPane = getContentPane(); contentPane.add(p, BorderLayout.NORTH); label = new JLabel(prefix + suffix); contentPane.add(label, BorderLayout.CENTER); setSubject("fox"); }
From source file:ListIt.java
public ListIt() { JFrame f = new JFrame(); final PartsListModel pcm = new PartsListModel(); ListCellRenderer lcr = new MyLabelRenderer(); JList jl = new JList(pcm); jl.setCellRenderer(lcr);//from w ww. j av a2s.c o m ListSelectionModel lsm = jl.getSelectionModel(); lsm.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jl.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { String element[] = (String[]) pcm.getElementAt(e.getFirstIndex()); System.out.println(element[0] + " : " + element[1] + " : " + element[2]); } } }); JScrollPane jsp = new JScrollPane(jl); JComboBox jc = new JComboBox(pcm); jc.setRenderer(lcr); JButton jb = new JButton("Add Merchandise"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { pcm.addElement(partsList[(int) (Math.random() * partsList.length)]); } }); Container c = f.getContentPane(); c.add(jsp, BorderLayout.NORTH); c.add(jc, BorderLayout.CENTER); c.add(jb, BorderLayout.SOUTH); f.setSize(250, 250); f.show(); }
From source file:ListTest.java
public ListFrame() { setTitle("ListTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); String[] words = { "quick", "brown", "hungry", "wild", "silent", "huge", "private", "abstract", "static", "final" }; wordList = new JList(words); wordList.setVisibleRowCount(4);// w ww . ja v a 2 s . c o m JScrollPane scrollPane = new JScrollPane(wordList); listPanel = new JPanel(); listPanel.add(scrollPane); wordList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { Object[] values = wordList.getSelectedValues(); StringBuilder text = new StringBuilder(prefix); for (int i = 0; i < values.length; i++) { String word = (String) values[i]; text.append(word); text.append(" "); } text.append(suffix); label.setText(text.toString()); } }); buttonPanel = new JPanel(); group = new ButtonGroup(); makeButton("Vertical", JList.VERTICAL); makeButton("Vertical Wrap", JList.VERTICAL_WRAP); makeButton("Horizontal Wrap", JList.HORIZONTAL_WRAP); add(listPanel, BorderLayout.NORTH); label = new JLabel(prefix + suffix); add(label, BorderLayout.CENTER); add(buttonPanel, BorderLayout.SOUTH); }
From source file:com.android.tools.idea.wizard.ChooseFromFileListDialog.java
@Nullable @Override// w ww . jav a2 s . co m protected JComponent createCenterPanel() { final JBList list = new JBList(); list.setModel(getListModel(myFiles)); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { myChosenFile = (FileListItem) list.getSelectedValue(); } }); return ListWithFilter.wrap(list); }
From source file:feelings.analyser.views.MainView.java
public void init() { ExtractData data = new ExtractData(); CleanData datatoClean = new CleanData(); String[] textAnalyzer = new String[100]; String textClean = ""; String absolutUrl = System.getProperty("user.dir"); File file = new File("Comentarios Mochila.txt"); JOptionPane.showInputDialog(this, absolutUrl + "\\src\\assets\\Comentarios Mochila.txt"); data.readFile(file);// w ww . ja va2s. c o m AnalyzerText analyzertext = new AnalyzerText(); for (String a : data.getPosts()) { datatoClean.setStreamToClean(a); datatoClean.textToLowerCase(); textClean = datatoClean.removeAcentos(); textClean = datatoClean.removePuntuationMarks(textClean); analyzertext.setPostToAnalyse(textClean); analyzertext.textAnalyze(); dataAnalyzer = new ResultDataAnalyzer(a, analyzertext.getPositiveCount(), analyzertext.getNegativeCount()); modelList.addElement(dataAnalyzer); System.out.println(textClean + "Buenas: " + analyzertext.getPositiveCount() + "Malas: " + analyzertext.getNegativeCount()); } lstPosts.setModel(modelList); lstPosts.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { ResultDataAnalyzer o = new ResultDataAnalyzer(); o = (ResultDataAnalyzer) lstPosts.getModel().getElementAt(e.getFirstIndex()); auxPositive = o.getCountPositive(); auxNegative = o.getCountNegative(); dividendo = auxPositive + auxNegative; dataChart.setValue("Positivo", (auxPositive / dividendo) * 10); dataChart.setValue("Negativo", (auxNegative / dividendo) * 10); } }); }
From source file:com.anrisoftware.prefdialog.miscswing.lists.ActionList.java
private void setupList() { list.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override/*from w w w .j a v a 2s .c o m*/ public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { fireAction(); } } }); list.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { fireAction(); } }); list.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getExtendedKeyCode() == KeyEvent.VK_SPACE) { fireAction(); } if (e.getExtendedKeyCode() == KeyEvent.VK_ENTER) { fireAction(); } } }); }
From source file:com.mirth.connect.connectors.jms.JmsConnectorPanel.java
public JmsConnectorPanel() { parent = PlatformUI.MIRTH_FRAME;// w w w .j a v a 2 s. c om initComponents(); connectionPropertiesTable.setNewButton(newButton); connectionPropertiesTable.setDeleteButton(deleteButton); connectionPropertiesTable.getPropertyColumn().setMinWidth(PROPERTY_COLUMN_WIDTH); connectionPropertiesTable.getPropertyColumn().setMaxWidth(PROPERTY_COLUMN_WIDTH); templateList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { Object templateName = templateList.getSelectedValue(); if (templateName == null) { loadTemplateButton.setEnabled(false); deleteTemplateButton.setEnabled(false); } else { loadTemplateButton.setEnabled(true); deleteTemplateButton.setEnabled(!listModel.isPredefinedTemplate(templateName.toString())); } } }); templateList.setCellRenderer(new TemplateListCellRenderer()); }
From source file:JListDemo.java
JListDemo(String s) { super(s);/*from w w w.j a v a2 s . c o m*/ Container cp = getContentPane(); cp.setLayout(new FlowLayout()); ArrayList data = new ArrayList(); data.add("Hi"); data.add("Hello"); data.add("Goodbye"); data.add("Adieu"); data.add("Adios"); list = new JList(data.toArray()); list.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { if (evt.getValueIsAdjusting()) return; System.out.println("Selected from " + evt.getFirstIndex() + " to " + evt.getLastIndex()); } }); cp.add(list, BorderLayout.CENTER); }
From source file:feedsplugin.FeedsSettingsTab.java
public JPanel createSettingsPanel() { final EnhancedPanelBuilder panelBuilder = new EnhancedPanelBuilder( FormFactory.RELATED_GAP_COLSPEC.encode() + ", fill:default:grow"); final CellConstraints cc = new CellConstraints(); mListModel = new DefaultListModel(); for (String feed : mSettings.getFeeds()) { mListModel.addElement(feed);//from www .j av a 2 s. com } mFeeds = new JList(mListModel); mFeeds.setSelectedIndex(0); mFeeds.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); mFeeds.addListSelectionListener(new ListSelectionListener() { public void valueChanged(final ListSelectionEvent e) { listSelectionChanged(); } }); panelBuilder.addGrowingRow(); panelBuilder.add(new JScrollPane(mFeeds), cc.xyw(2, panelBuilder.getRow(), panelBuilder.getColumnCount() - 1)); mAdd = new JButton(mLocalizer.msg("add", "Add feed")); mAdd.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { String genre = JOptionPane.showInputDialog(mLocalizer.msg("addMessage", "Add feed URL"), ""); if (genre != null) { genre = genre.trim(); if (genre.length() > 0) { mListModel.addElement(genre); } } } }); mRemove = new JButton(mLocalizer.msg("remove", "Remove feed")); mRemove.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { final int index = mFeeds.getSelectedIndex(); if (index >= 0) { mListModel.remove(index); } } }); panelBuilder.addRow(); ButtonBarBuilder2 buttonBar = new ButtonBarBuilder2(); buttonBar.addButton(new JButton[] { mAdd, mRemove }); panelBuilder.add(buttonBar.getPanel(), cc.xyw(2, panelBuilder.getRow(), panelBuilder.getColumnCount() - 1)); mFeeds.addListSelectionListener(new ListSelectionListener() { public void valueChanged(final ListSelectionEvent e) { mRemove.setEnabled(mFeeds.getSelectedIndex() >= 0); } }); panelBuilder.addParagraph(mLocalizer.msg("moreFeeds", "Get more feeds")); panelBuilder.addRow(); JEditorPane help = UiUtilities.createHtmlHelpTextArea(mLocalizer.msg("help", "You can find more news feeds on the <a href=\"{0}\">plugin help page</a>. If you know more interesting feeds, feel free to add them on that page.", StringUtils.replace(PluginInfo.getHelpUrl(FeedsPlugin.getInstance().getId()), "&", "&"))); panelBuilder.add(help, cc.xyw(2, panelBuilder.getRow(), panelBuilder.getColumnCount() - 1)); // force update of enabled states listSelectionChanged(); return panelBuilder.getPanel(); }
From source file:com.intuit.tank.tools.debugger.SelectDialog.java
/** * @param arg0/*from w w w .j av a 2 s.c o m*/ */ public SelectDialog(Frame f, List<SELECTION_TYPE> items, String itemType, boolean singleSelection) { super(f, true); setLayout(new BorderLayout()); this.items = items; filterField = new JTextField(); filterField.addKeyListener(new KeyHandler()); list = new JList(items.toArray()); list.setSelectionMode(singleSelection ? ListSelectionModel.SINGLE_SELECTION : ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { okBT.setEnabled(list.getSelectedIndex() != -1); } }); list.addMouseListener(new MouseAdapter() { /** * @{inheritDoc */ @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { select(); } } }); JPanel labelPanel = new JPanel(new GridLayout(singleSelection ? 1 : 2, 1, 0, 5)); labelPanel.add(new JLabel("Select a " + itemType + ".")); if (!singleSelection) { String key = System.getProperty("os.name").toLowerCase().indexOf("mac") != -1 ? "" : "control"; System.out.println(key); labelPanel.add(new JLabel("Hold down the " + key + " key to select multiple " + itemType + ".")); } add(labelPanel, BorderLayout.NORTH); JScrollPane sp = new JScrollPane(list); JPanel centerPanel = new JPanel(new BorderLayout()); centerPanel.add(filterField, BorderLayout.NORTH); centerPanel.add(sp, BorderLayout.CENTER); add(centerPanel, BorderLayout.CENTER); add(createButtonPanel(), BorderLayout.SOUTH); setSize(new Dimension(400, 500)); setBounds(new Rectangle(getSize())); setPreferredSize(getSize()); WindowUtil.centerOnParent(this); }