List of usage examples for javax.swing JList setVisibleRowCount
@BeanProperty(visualUpdate = true, description = "The preferred number of rows to display without requiring scrolling") public void setVisibleRowCount(int visibleRowCount)
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(); panel.setPreferredSize(new Dimension(800, 600)); String test[] = { "alpha", "bravo", "charlie", "delta", "echo", "omega", "zeta" }; JList<String> list = new JList<>(test); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setLayoutOrientation(JList.VERTICAL); list.setVisibleRowCount(5); list.setBounds(50, 150, 75, 90);//from ww w. j av a 2 s . com JScrollPane jScrollPane1 = new JScrollPane(); jScrollPane1.setViewportView(list); panel.add(jScrollPane1); JFrame f = new JFrame(); f.add(panel); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setResizable(false); f.setFocusable(true); }
From source file:Main.java
public static void main(String[] args) { DefaultListModel<String> model = new DefaultListModel<>(); JList<String> sList = new JList<>(model); for (int i = 0; i < 100; i++) { model.addElement("String " + i); }//from w w w . j ava 2 s . c om sList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); sList.setVisibleRowCount(-1); sList.setLayoutOrientation(JList.HORIZONTAL_WRAP); JFrame frame = new JFrame("Foo001"); frame.getContentPane().add(new JScrollPane(sList)); frame.getContentPane().setPreferredSize(new Dimension(400, 300)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JDialog dialog;// w w w .j a v a 2 s . c om JList jlist; ActionListener otherListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("current"); } }; JButton okButton = new JButton("OK"); okButton.addActionListener(e -> close(true)); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(e -> close(false)); jlist = new JList(new String[] { "A", "B", "C", "D", "E", "F", "G" }); jlist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jlist.setVisibleRowCount(5); JScrollPane scroll = new JScrollPane(jlist); JPanel buttonsPanel = new JPanel(new FlowLayout()); buttonsPanel.add(okButton); buttonsPanel.add(cancelButton); JPanel content = new JPanel(new BorderLayout()); content.add(scroll, BorderLayout.CENTER); content.add(buttonsPanel, BorderLayout.SOUTH); dialog = new JDialog((Frame) null, true); dialog.setContentPane(content); dialog.pack(); dialog.getRootPane().registerKeyboardAction(otherListener, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); dialog.getRootPane().registerKeyboardAction(otherListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); dialog.getRootPane().getInputMap().put(KeyStroke.getKeyStroke("SPACE"), "doSomething"); dialog.getRootPane().getActionMap().put("doSomething", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); dialog.setVisible(true); }
From source file:Main.java
public static JList getListBarChart() { JList list = new JList(); list.setVisibleRowCount(-1); list.setBackground(Color.WHITE); return list;//from ww w .ja va 2 s . co m }
From source file:Main.java
public Main() { setLayout(new GridLayout(1, 2)); String[] numbers = { "one", "two", "three", "four", "five", "six", "seven" }; JList<String> list = new JList<>(numbers); list.setVisibleRowCount(1); list.addListSelectionListener(this); JScrollPane s = new JScrollPane(list); s.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); s.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); add(s);// w w w. j a va 2s . c om list.setSelectedIndex(3); }
From source file:csh.vctt.launcher.Launcher.java
/** * Prompt the user to select their character from a dialog. * @return Unique id number of the selected character. *//*w w w . j a va 2 s. c o m*/ private String getPlayerSelection() { String selectedId = "-1"; String outfitMembersJson = DataManager.execQuery(DataManager.M_OUTFITMEMBER_SELECT_QUERY); List<Player> outfitMembers = DataManager.getOutfitMembers(outfitMembersJson); Object[] outfitMembersArrObj = outfitMembers.toArray(); Player[] outfitMembersArr = new Player[outfitMembersArrObj.length]; for (int i = 0; i < outfitMembersArrObj.length; i++) { outfitMembersArr[i] = (Player) outfitMembersArrObj[i]; } JList<Player> memSelList = new JList<Player>(outfitMembersArr); memSelList.setVisibleRowCount(10); JScrollPane memScrollPane = new JScrollPane(memSelList); memScrollPane.setPreferredSize(new Dimension(200, 400)); int userAction = JOptionPane.showConfirmDialog(null, memScrollPane, "Select Character and Press Ok", JOptionPane.PLAIN_MESSAGE); Player selectedPlayer = null; if (userAction == JOptionPane.YES_OPTION) { selectedPlayer = memSelList.getSelectedValue(); } if (selectedPlayer != null) { selectedId = selectedPlayer.getId(); } return selectedId; }
From source file:com.frostwire.gui.library.LibraryFilesTableMediator.java
/** * Creates a JList of files and sets and makes it non-selectable. *//*from ww w . jav a2 s. c o m*/ private static JList<String> createFileList(List<String> fileNames) { JList<String> fileList = new JList<String>(fileNames.toArray(new String[0])); fileList.setVisibleRowCount(5); fileList.setCellRenderer(new FileNameListCellRenderer()); //fileList.setSelectionForeground(fileList.getForeground()); //fileList.setSelectionBackground(fileList.getBackground()); fileList.setFocusable(false); return fileList; }
From source file:com.projity.pm.graphic.chart.ChartLegend.java
private void setListFields(JList list, boolean cost) { Object[] items = getFields(cost); list.setListData(items);/*from w w w . ja v a 2 s . c om*/ list.setVisibleRowCount(items.length); if (simple) { list.setSelectionInterval(0, items.length); list.setEnabled(false); // in simple mode, no selection allowed } }
From source file:it.cnr.icar.eric.client.ui.swing.RegistryObjectsTable.java
@SuppressWarnings("unchecked") private void addRenderers() { try {//from www . j ava2 s.com setDefaultRenderer(Class.forName("java.lang.Object"), new JBDefaultTableCellRenderer()); setDefaultRenderer(Class.forName("java.util.Collection"), new CollectionRenderer()); final JList<Object> list = new JList<Object>(); list.setVisibleRowCount(3); list.setOpaque(true); list.setCellRenderer(new ListDefaultRenderer()); list.addListSelectionListener(new ListSelectionListener() { @SuppressWarnings({ "static-access", "unused" }) public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { Object obj = list.getSelectedValue(); obj = RegistryObjectsTable.this.convertValue(obj); if (obj instanceof URL) { HyperLinker.displayURL(obj.toString()); } else if (obj instanceof String) { //Check if URL is valid URL _url = null; try { _url = new URL(obj.toString()); HyperLinker.displayURL(obj.toString()); } catch (MalformedURLException exc) { //No need to do anything. It is normal for text to not be a URL _url = null; } } } } }); JScrollPane listPane = new JScrollPane(list); setDefaultEditor(Class.forName("java.util.Collection"), new JBDefaultCellEditor(listPane)); HyperLinkLabel hyperLinkLabel = new HyperLinkLabel(); hyperLinkLabel.setHorizontalAlignment(SwingConstants.TRAILING); setDefaultEditor(Class.forName("java.lang.Object"), new JBDefaultCellEditor(hyperLinkLabel)); } catch (ClassNotFoundException e) { return; } }
From source file:com.googlecode.vfsjfilechooser2.filepane.VFSFilePane.java
private void updateListRowCount(JList list) { if (smallIconsView) { list.setVisibleRowCount(getModel().getSize() / 3); } else {/* www . jav a2 s .c om*/ list.setVisibleRowCount(-1); } }