List of usage examples for javax.swing ListSelectionModel SINGLE_SELECTION
int SINGLE_SELECTION
To view the source code for javax.swing ListSelectionModel SINGLE_SELECTION.
Click Source Link
From source file:userinterface.CyberSecurity.CyberSecurityJPanel.java
private void init() { employeeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); populateOrganizationComboBox();//from w ww.j a va 2 s .com populateEmployeeInfo(); organizationComboBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { organizationJComboBoxActionPerformed(evt); } }); btnLoadAllEmployees.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnLoadAllEmployeesActionPerformed(evt); } }); initPage(); }
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 w w . j a v a 2 s .com*/ 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:components.SplitPaneDemo.java
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);/*from ww w . ja v a 2 s . com*/ 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()]); }
From source file:com.intuit.tank.tools.debugger.VariableDialog.java
public VariableDialog(AgentDebuggerFrame f, Map<String, String> variables) { super(f, true); this.f = f;//from w w w. j ava2 s. com setLayout(new BorderLayout()); setTitle("View Edit Project Variables"); DefaultTableModel model = new DefaultTableModel(); model.addColumn("Variable Name"); model.addColumn("Variable Value"); List<String> keys = new ArrayList<String>(variables.keySet()); Collections.sort(keys); for (String key : keys) { Object[] data = new Object[2]; data[0] = key; data[1] = variables.get(key); model.addRow(data); } table = new JTable(model); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.getSelectionModel().addListSelectionListener(this); table.setGridColor(Color.GRAY); table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); table.setBorder(BorderFactory.createLineBorder(Color.GRAY)); table.setShowGrid(true); table.getTableHeader().setReorderingAllowed(false); JScrollPane sp = new JScrollPane(table); JPanel panel = new JPanel(new BorderLayout()); panel.add(table.getTableHeader(), BorderLayout.NORTH); panel.add(sp, BorderLayout.CENTER); add(panel, BorderLayout.CENTER); add(createButtonPanel(), BorderLayout.SOUTH); setSize(new Dimension(800, 600)); setBounds(new Rectangle(getSize())); setPreferredSize(getSize()); WindowUtil.centerOnParent(this); }
From source file:dk.dma.ais.virtualnet.transponder.gui.SelectTargetList.java
/** * Constructor//from w w w. j av a 2s . co m */ public SelectTargetList() { super(); setSelectionMode(ListSelectionModel.SINGLE_SELECTION); setLayoutOrientation(JList.VERTICAL); setModel(new TargetFilterModel()); filterField = new TargetFilterField(DEFAULT_FIELD_WIDTH); }
From source file:CheckBoxList.java
public CheckBoxList() { super();//from ww w. j ava 2s .com setModel(new DefaultListModel()); setCellRenderer(new CheckboxCellRenderer()); addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { int index = locationToIndex(e.getPoint()); if (index != -1) { Object obj = getModel().getElementAt(index); if (obj instanceof JCheckBox) { JCheckBox checkbox = (JCheckBox) obj; checkbox.setSelected(!checkbox.isSelected()); repaint(); } } } } ); setSelectionMode(ListSelectionModel.SINGLE_SELECTION); }
From source file:com.android.tools.idea.wizard.ChooseFromFileListDialog.java
@Nullable @Override/*w ww. j av a2s . c o 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:com.emental.mindraider.ui.outline.OutlineArchiveJPanel.java
public OutlineArchiveJPanel() { setLayout(new BorderLayout()); // table with archived concepts (title) // let table model to load discarded concepts itself tableModel = new ArchiveTableModel(this); table = new JTable(tableModel); table.setAutoCreateRowSorter(true);/*from w w w .j a va 2 s . co m*/ JScrollPane scroll = new JScrollPane(table); table.setFillsViewportHeight(true); table.setShowHorizontalLines(false); table.setShowVerticalLines(false); table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); JToolBar toolbar = new JToolBar(); undoButton = new JButton("", IconsRegistry.getImageIcon("trashUndo.png")); undoButton.setEnabled(false); undoButton.setToolTipText("Restore Note"); undoButton.addActionListener(new UndiscardConceptActionListener(tableModel, table)); toolbar.add(undoButton); deleteButton = new JButton("", IconsRegistry.getImageIcon("explorerDeleteSmall.png")); deleteButton.setEnabled(true); deleteButton.setToolTipText("Delete Note"); deleteButton.addActionListener(new DeleteConceptActionListener(tableModel, table)); toolbar.add(deleteButton); purgeButton = new JButton("", IconsRegistry.getImageIcon("trashFull.png")); purgeButton.setEnabled(true); purgeButton.setToolTipText("Empty Notes Archive"); purgeButton.addActionListener(new EmptyArchiveActionListener()); toolbar.add(purgeButton); add(toolbar, BorderLayout.NORTH); add(scroll, BorderLayout.CENTER); }
From source file:com.sec.ose.osi.ui.frm.main.identification.codematch.table.JTableInfoForCMFolder.java
public JTableInfoForCMFolder() { this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); this.setModel(FORDER_TABLE_MODEL); this.setDefaultRenderer(this.getColumnClass(0), renderer); initSorter();//from www. j ava2 s .c o m }
From source file:com.intuit.tank.tools.debugger.SelectDialog.java
/** * @param arg0/*ww w. j av a2s . co 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); }