List of usage examples for javax.swing JList getSelectedValue
@BeanProperty(bound = false)
public E getSelectedValue()
From source file:org.nebulaframework.ui.swing.node.NodeMainUI.java
/** * Setup Job History Tab Pane// w w w . j a v a 2s. c o m * * @return JPanel for History tab */ private JPanel setupHistory() { JPanel historyPanel = new JPanel(); historyPanel.setLayout(new BorderLayout(10, 10)); /* -- Job List -- */ JPanel jobListPanel = new JPanel(); historyPanel.add(jobListPanel, BorderLayout.CENTER); jobListPanel.setLayout(new BorderLayout(10, 10)); jobListPanel.setBorder(BorderFactory.createTitledBorder("Grid Jobs")); final JList jobList = new JList(historyList); JScrollPane jobListScroll = new JScrollPane(jobList); jobListPanel.add(jobListScroll, BorderLayout.CENTER); jobListScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); jobListScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); addUIElement("history.joblist", jobList); jobList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jobList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { // Ignore intermediate events if (e.getValueIsAdjusting()) return; displayJobInfo(jobList.getSelectedValue()); } }); JPanel jobInfoPanel = new JPanel(); historyPanel.add(jobInfoPanel, BorderLayout.SOUTH); jobInfoPanel.setLayout(new BorderLayout(10, 10)); jobInfoPanel.setBorder(BorderFactory.createTitledBorder("Job Information")); JPanel centerPanel = new JPanel(); jobInfoPanel.add(centerPanel, BorderLayout.CENTER); centerPanel.setLayout(new GridLayout(0, 4, 10, 10)); JLabel jobIdLabel = new JLabel("GridJob ID :"); centerPanel.add(jobIdLabel); JLabel jobId = new JLabel("N/A"); centerPanel.add(jobId); addUIElement("history.jobid", jobId); // Add to components map JLabel jobNameLabel = new JLabel("GridJob Name :"); centerPanel.add(jobNameLabel); JLabel jobName = new JLabel("N/A"); centerPanel.add(jobName); addUIElement("history.jobname", jobName); // Add to components map JLabel startTimeLabel = new JLabel("Start Time :"); centerPanel.add(startTimeLabel); JLabel startTime = new JLabel("N/A"); centerPanel.add(startTime); addUIElement("history.starttime", startTime); // Add to components map JLabel durationLabel = new JLabel("Duration :"); centerPanel.add(durationLabel); JLabel duration = new JLabel("N/A"); centerPanel.add(duration); addUIElement("history.duration", duration); // Add to components map JLabel tasksLabel = new JLabel("Tasks Executed :"); centerPanel.add(tasksLabel); JLabel tasks = new JLabel("N/A"); centerPanel.add(tasks); addUIElement("history.tasks", tasks); // Add to components map JLabel failuresLabel = new JLabel("Failures :"); centerPanel.add(failuresLabel); JLabel failures = new JLabel("N/A"); centerPanel.add(failures); addUIElement("history.failures", failures); // Add to components map // Place Holders centerPanel.add(new JLabel()); centerPanel.add(new JLabel()); return historyPanel; }
From source file:org.yccheok.jstock.gui.IndicatorPanel.java
private void syncJListWithIndicatorProjectManager(JList jList, IndicatorProjectManager indicatorProjectManager) { final String projectName = (String) jList.getSelectedValue(); boolean isProjectNameBeingRemoved = false; int newSelection = -1; final ListModel listModel = jList.getModel(); for (int i = 0; i < listModel.getSize(); i++) { if (indicatorProjectManager.contains(listModel.getElementAt(i).toString()) == false) { // Remove from JList, as it is not found in indicator project manager. Object removedObject = ((DefaultListModel) listModel).remove(i); if (projectName.equals(removedObject)) { isProjectNameBeingRemoved = true; newSelection = i;//from w w w. j a v a 2s .c om } i--; } } for (int i = 0; i < indicatorProjectManager.getNumOfProject(); i++) { final String p = indicatorProjectManager.getProject(i); if (((DefaultListModel) listModel).contains(p) == false) { // Add to JList, as it is found in indicator project manager. ((DefaultListModel) listModel).addElement(p); } } if (!isProjectNameBeingRemoved) { // Ensure list cell renderer is being triggered. jList.setSelectedValue(projectName, true); } else { if (newSelection >= jList.getModel().getSize()) { // Select last row. jList.setSelectedIndex(jList.getModel().getSize() - 1); } else { jList.setSelectedIndex(newSelection); } } }