Java Code Examples for javax.swing.JList#setSelectedValue()
The following examples show how to use
javax.swing.JList#setSelectedValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BBoxDBGui.java From bboxdb with Apache License 2.0 | 5 votes |
/** * Generate the left panel * @return */ private JComponent getLeftPanel() { final DefaultListModel<String> listModel = new DefaultListModel<String>(); final JList<String> distributionGroupList = new JList<String>(listModel); refreshDistributionGroups(listModel); distributionGroupList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); distributionGroupList.setSelectedValue(guiModel.getDistributionGroup(), true); distributionGroupList.addListSelectionListener(e -> { if (! e.getValueIsAdjusting()) { guiModel.setDistributionGroup(distributionGroupList.getSelectedValue()); updateMainPanel(); } }); final JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.add(distributionGroupList, BorderLayout.CENTER); final JButton reloadItem = new JButton("Reload"); reloadItem.addActionListener((e) -> { refreshDistributionGroups(listModel); updateMainPanel(); }); panel.add(reloadItem, BorderLayout.SOUTH); return panel; }
Example 2
Source File: NullpoMinoSwing.java From nullpomino with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Init top screen */ protected void initTopScreenUI(JComponent p) { p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); // Label lModeSelect = new JLabel(getUIText("Top_ModeSelect")); lModeSelect.setAlignmentX(0f); p.add(lModeSelect); // Mode & rule select panel JPanel subpanelModeSelect = new JPanel(new BorderLayout()); subpanelModeSelect.setBorder(new EtchedBorder()); subpanelModeSelect.setAlignmentX(0f); p.add(subpanelModeSelect); // * Mode select listbox listboxMode = new JList(modeList); listboxMode.addMouseListener(new ListboxModeMouseAdapter()); listboxMode.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { String strMode = (String)listboxMode.getSelectedValue(); lModeSelect.setText(getModeDesc(strMode)); prepareRuleList(strMode); } }); JScrollPane scpaneListboxMode = new JScrollPane(listboxMode); scpaneListboxMode.setPreferredSize(new Dimension(280, 375)); subpanelModeSelect.add(scpaneListboxMode, BorderLayout.WEST); // * Rule select listbox listmodelRule = new DefaultListModel(); listboxRule = new JList(listmodelRule); listboxRule.addMouseListener(new ListboxModeMouseAdapter()); JScrollPane scpaneListBoxRule = new JScrollPane(listboxRule); scpaneListBoxRule.setPreferredSize(new Dimension(150, 375)); subpanelModeSelect.add(scpaneListBoxRule, BorderLayout.CENTER); // * Set default selected index listboxMode.setSelectedValue(propGlobal.getProperty("name.mode", ""), true); if(listboxMode.getSelectedIndex() == -1) listboxMode.setSelectedIndex(0); prepareRuleList((String)listboxMode.getSelectedValue()); // Start button JButton buttonStartOffline = new JButton(getUIText("Top_StartOffline")); buttonStartOffline.setMnemonic('S'); buttonStartOffline.addActionListener(this); buttonStartOffline.setActionCommand("Top_StartOffline"); buttonStartOffline.setAlignmentX(0f); buttonStartOffline.setMaximumSize(new Dimension(Short.MAX_VALUE, buttonStartOffline.getMaximumSize().height)); p.add(buttonStartOffline); this.getRootPane().setDefaultButton(buttonStartOffline); // Menu initMenu(); }