本文整理匯總了Java中javax.swing.JList.setSelectionMode方法的典型用法代碼示例。如果您正苦於以下問題:Java JList.setSelectionMode方法的具體用法?Java JList.setSelectionMode怎麽用?Java JList.setSelectionMode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JList
的用法示例。
在下文中一共展示了JList.setSelectionMode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildListFromComponents
import javax.swing.JList; //導入方法依賴的package包/類
/**
* Builds a list from the components array.
* @param components the components array
* @return a list to be placed on the GUI
*/
JList buildListFromComponents (Component [] components) {
JList list = new JList();
if (components != null) {
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setSize(100,200);
listData = new Vector();
menuItems = new Hashtable();
// build a hash look-up table and fill list with components's text
for (int i=0 ; i<components.length ; i++) {
if (components[i] instanceof JMenuItem) {
listData.addElement(((JMenuItem)components[i]).getText());
menuItems.put(((JMenuItem)components[i]).getText(),components[i]);
}
else {
listData.addElement(SEPARATOR_STRING);
menuItems.put(SEPARATOR_STRING,components[i]);
}
}
list.setListData(listData);
}
return list;
}
示例2: makeList
import javax.swing.JList; //導入方法依賴的package包/類
private JList<String> makeList(final String[][] items, int visibleRows, Container parent) {
JList<String> list = new JList<>(new AbstractListModel<String>() {
/**
*
*/
private static final long serialVersionUID = 6510576197401709714L;
public String getElementAt(int i) {
return items[i][0];
}
public int getSize() {
return items.length;
}
});
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setVisibleRowCount(visibleRows);
parent.add(new JScrollPane(list));
return list;
}
示例3: initComponents
import javax.swing.JList; //導入方法依賴的package包/類
private void initComponents() {
setLayout(new BorderLayout(5, 5));
this.setBorder(new EmptyBorder(20, 20, 20, 20));
//classesList = new JList(new StationsListModel());
stationsList = new JList();
stationsList.setListData(stationData.getStationKeys());
stationsList.setCellRenderer(new StationElementRenderer());
stationsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
panelDescription = new JLabel(STATIONS_PAR_DESCRIPTION);
JScrollPane jsp = new JScrollPane(stationsList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jsp.setPreferredSize(new Dimension(140, 200));
add(panelDescription, BorderLayout.NORTH);
add(jsp, BorderLayout.WEST);
stationsList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
updateParsPane();
}
});
}
示例4: PluginDialog
import javax.swing.JList; //導入方法依賴的package包/類
public PluginDialog()
{
listModel = new DefaultListModel();
list = new JList();
list.setModel(listModel);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
for( String name : plugins.keySet() )
{
listModel.addElement(name);
}
setLayout(new BorderLayout());
add(new JScrollPane(list));
}
示例5: initComponents
import javax.swing.JList; //導入方法依賴的package包/類
protected void initComponents() {
services = RunCentralisedMAS.getRunner().getRuntimeServices();
getContentPane().setLayout(new BorderLayout());
// Fields
Vector<String> agNames = new Vector<String>(services.getAgentsNames());
Collections.sort(agNames);
lAgs = new JList(agNames);
lAgs.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
JPanel p = new JPanel(new BorderLayout());
p.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Current agents", TitledBorder.LEFT, TitledBorder.TOP));
p.add(lAgs, BorderLayout.CENTER);
getContentPane().add(p, BorderLayout.CENTER);
getContentPane().add(createButtonsPanel(), BorderLayout.SOUTH);
ok.setText("Kill");
}
示例6: createLeft
import javax.swing.JList; //導入方法依賴的package包/類
private Component createLeft() {
usedUnits = new JList(usedUnitsModel);
usedUnits.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
usedUnits.setVisibleRowCount(rowCount);
usedUnits.addListSelectionListener(new UsedSelector());
leftListPane = new JScrollPane(usedUnits);
return leftListPane;
}
示例7: FlagsEditorPanel
import javax.swing.JList; //導入方法依賴的package包/類
/** Creates a new instance of FlagsEditorPanel */
public FlagsEditorPanel(String flagString) {
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
listModel = new FlagListModel(flagString);
list = new JList(listModel);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addListSelectionListener(this);
add(new JScrollPane(list));
add(Box.createHorizontalStrut(3));
Box buttonBox = new Box(BoxLayout.Y_AXIS);
buttonBox.add(colorButton = new ColorChooserButton());
buttonBox.add(newButton = new JButton("New..."));
buttonBox.add(removeButton = new JButton("Remove"));
buttonBox.add(upButton = new JButton("Up"));
buttonBox.add(downButton = new JButton("Down"));
buttonBox.add(Box.createVerticalGlue());
add(buttonBox);
layoutButtonContainer(buttonBox);
colorButton.setColorChooserEnabled(false);
colorButton.addActionListener(this);
newButton.addActionListener(this);
removeButton.addActionListener(this);
upButton.addActionListener(this);
downButton.addActionListener(this);
selectionChanged(-1); // no selection
}
示例8: createNewConfigurableJList
import javax.swing.JList; //導入方法依賴的package包/類
/**
* Creates a new JList for a given source of a configurable
*
* @param source
* can be null for local configurables, otherwise name of the source
* @return the created JList
*/
private JList<Configurable> createNewConfigurableJList(String source) {
final JList<Configurable> createdConfigList = new JList<>();
createdConfigList.setModel(source == null ? localConfigListModel : remoteConfigListModels.get(source));
createdConfigList.setCellRenderer(new ConfigurableRenderer());
createdConfigList.setFixedCellHeight(40);
createdConfigList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
createdConfigList.setBackground(LIGHTER_GRAY);
return createdConfigList;
}
示例9: initComponents
import javax.swing.JList; //導入方法依賴的package包/類
private void initComponents() {
setLayout(new BorderLayout(5, 5));
this.setBorder(new EmptyBorder(20, 20, 20, 20));
//classesList = new JList(new StationsListModel());
stationsList = new JList();
stationsList.setListData(stationData.getStationKeys());
stationsList.setCellRenderer(new StationElementRenderer());
stationsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
panelDescription = new JLabel(STATIONS_PAR_DESCRIPTION);
JScrollPane jsp = new JScrollPane(stationsList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jsp.setPreferredSize(new Dimension(140, 200));
add(panelDescription, BorderLayout.NORTH);
add(jsp, BorderLayout.WEST);
stationsList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
updateParsPane();
}
});
}
示例10: createList
import javax.swing.JList; //導入方法依賴的package包/類
private JPanel createList() {
DefaultListModel listModel = new DefaultListModel();
for (int i = 0; i < 10; i++) {
listModel.addElement("List Item " + i);
}
list = new JList(listModel);
list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
JScrollPane scrollPane = new JScrollPane(list);
scrollPane.setPreferredSize(new Dimension(400, 100));
list.setDragEnabled(true);
list.setTransferHandler(new ListTransferHandler());
dropCombo = new JComboBox(new String[] { "USE_SELECTION", "ON", "INSERT", "ON_OR_INSERT" });
dropCombo.addActionListener(this);
JPanel dropPanel = new JPanel();
dropPanel.add(new JLabel("List Drop Mode:"));
dropPanel.add(dropCombo);
JPanel panel = new JPanel(new BorderLayout());
panel.add(scrollPane, BorderLayout.CENTER);
panel.add(dropPanel, BorderLayout.SOUTH);
panel.setBorder(BorderFactory.createTitledBorder("List"));
return panel;
}
示例11: LHSListPane
import javax.swing.JList; //導入方法依賴的package包/類
public LHSListPane(Container paneParent, JList lst)
{
lst.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
setViewportView(lst);
int nWidth = (int) ((double) paneParent.getWidth() * PERCENTAGE_WIDTH);
setSize(nWidth, paneParent.getHeight());
}
示例12: createRight
import javax.swing.JList; //導入方法依賴的package包/類
private Component createRight() {
for (int i = 0; i < allUnitStrings.length; i++) {
selectedUnitsSet.addElement(allUnitStrings[i]);
}
allUnits = new JList(selectedUnitsSet);
allUnits.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
allUnits.setVisibleRowCount(rowCount);
allUnits.addListSelectionListener(new AllSelector());
rightListPane = new JScrollPane(allUnits);
return rightListPane;
}
示例13: getEntryArea
import javax.swing.JList; //導入方法依賴的package包/類
/** Lazily creates and returns the panel. */
private JList<SelectableListEntry> getEntryArea() {
if (this.entryArea == null) {
JList<SelectableListEntry> result = this.entryArea = new JList<>();
result.setBackground(getColors().getBackground(Mode.NONE));
result.setForeground(getColors().getForeground(Mode.NONE));
result.setSelectionBackground(getColors().getBackground(Mode.FOCUSED));
result.setSelectionForeground(getColors().getBackground(Mode.FOCUSED));
result.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
result.setCellRenderer(new CellRenderer());
}
return this.entryArea;
}
示例14: initGUI
import javax.swing.JList; //導入方法依賴的package包/類
/**
* Initializes GUI.
*/
private void initGUI() {
PrimListModel model = new PrimListModel();
JList<Integer> firstList = new JList<Integer>(model);
JList<Integer> secondList = new JList<Integer>(model);
JButton next = new JButton("Next");
firstList
.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
firstList.setLayoutOrientation(JList.VERTICAL);
JScrollPane firstScroller = new JScrollPane(firstList);
secondList
.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
secondList.setLayoutOrientation(JList.VERTICAL);
JScrollPane secondSroller = new JScrollPane(secondList);
next.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
model.next();
revalidate();
}
});
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
panel.add(firstScroller);
panel.add(secondSroller);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(panel, BorderLayout.CENTER);
getContentPane().add(next, BorderLayout.PAGE_END);
}
示例15: setup
import javax.swing.JList; //導入方法依賴的package包/類
private void setup()
{
JLabel label = new JLabel(CurrentLocale.get("com.tle.admin.workflow.stepdialog.title"));
model = new GenericListModel<Class<? extends WorkflowNode>>();
list = new JList(model);
list.setCellRenderer(new WorkflowCellRenderer());
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addListSelectionListener(this);
list.addMouseListener(this);
ok = new JButton(CurrentLocale.get("com.tle.admin.ok"));
cancel = new JButton(CurrentLocale.get("com.tle.admin.cancel"));
ok.addActionListener(this);
cancel.addActionListener(this);
final int height1 = label.getPreferredSize().height;
final int height2 = ok.getPreferredSize().height;
final int width1 = cancel.getPreferredSize().width;
final int[] rows = {height1, TableLayout.FILL, height2,};
final int[] cols = {TableLayout.FILL, width1, width1,};
content = new JPanel(new TableLayout(rows, cols));
content.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
content.add(label, new Rectangle(0, 0, 3, 1));
content.add(new JScrollPane(list), new Rectangle(0, 1, 3, 1));
content.add(ok, new Rectangle(1, 2, 1, 1));
content.add(cancel, new Rectangle(2, 2, 1, 1));
updateButtons();
}