List of usage examples for javax.swing JList JList
public JList(final Vector<? extends E> listData)
JList
that displays the elements in the specified Vector
. From source file:Main.java
public Main() { setLayout(new BorderLayout()); model = new DefaultListModel(); list = new JList(model); JScrollPane pane = new JScrollPane(list); JButton addButton = new JButton("Add Element"); JButton removeButton = new JButton("Remove Element"); for (int i = 0; i < 15; i++) model.addElement("Element " + i); addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { model.addElement("Element " + counter); counter++;//from w w w. jav a 2s.c om } }); removeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (model.getSize() > 0) model.removeElementAt(0); } }); add(pane, BorderLayout.NORTH); add(addButton, BorderLayout.WEST); add(removeButton, BorderLayout.EAST); }
From source file:ListModelExample.java
public ListModelExample() { setLayout(new BorderLayout()); model = new DefaultListModel(); list = new JList(model); JScrollPane pane = new JScrollPane(list); JButton addButton = new JButton("Add Element"); JButton removeButton = new JButton("Remove Element"); for (int i = 0; i < 15; i++) model.addElement("Element " + i); addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { model.addElement("Element " + counter); counter++;/*from w w w .j av a2s.c o m*/ } }); removeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (model.getSize() > 0) model.removeElementAt(0); } }); add(pane, BorderLayout.NORTH); add(addButton, BorderLayout.WEST); add(removeButton, BorderLayout.EAST); }
From source file:LongListTest.java
public LongListTest() { setTitle("LongListTest"); setSize(400, 300);// www . j a va 2 s . c o m addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); JList wordList = new JList(new WordListModel(300000)); wordList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); wordList.setFixedCellWidth(50); wordList.setFixedCellHeight(15); JScrollPane scrollPane = new JScrollPane(wordList); JPanel p = new JPanel(); p.add(scrollPane); wordList.addListSelectionListener(this); getContentPane().add(p, "Center"); getContentPane().add(label, "North"); }
From source file:ListTest.java
public ListTest() { setTitle("ListTest: Press control to multi-select"); setSize(400, 300);/*from w w w . j a va2s.c o m*/ addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); String[] words = { "quick", "brown", "hungry", "wild", "silent", "huge" }; JList wordList = new JList(words); JScrollPane scrollPane = new JScrollPane(wordList); JPanel p = new JPanel(); p.add(scrollPane); wordList.addListSelectionListener(this); getContentPane().add(p, "South"); getContentPane().add(label, "Center"); }
From source file:Main.java
public Main() { super("Swing List with Tab Renenderer"); setSize(500, 240);// w w w.j av a2 s.c o m String[] items = { "cloumn 1\t column 2\t Column 3", "cloumn 1\t column 2\t Column 3" }; list = new JList(items); TabListCellRenderer renderer = new TabListCellRenderer(); list.setCellRenderer(renderer); JScrollPane scrollPane = new JScrollPane(); scrollPane.getViewport().add(list); getContentPane().add(scrollPane, BorderLayout.CENTER); WindowListener exitEvent = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(exitEvent); setVisible(true); }
From source file:TabRenendererList.java
public TabRenendererList() { super("Swing List with Tab Renenderer"); setSize(500, 240);// w ww .jav a2 s . c om String[] items = { "cloumn 1\t column 2\t Column 3", "cloumn 1\t column 2\t Column 3" }; list = new JList(items); TabListCellRenderer renderer = new TabListCellRenderer(); list.setCellRenderer(renderer); JScrollPane scrollPane = new JScrollPane(); scrollPane.getViewport().add(list); getContentPane().add(scrollPane, BorderLayout.CENTER); WindowListener exitEvent = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(exitEvent); setVisible(true); }
From source file:SelectionMonitor.java
public SelectionMonitor() { setLayout(new BorderLayout()); list = new JList(label); JScrollPane pane = new JScrollPane(list); // Format the list and the buttons in a vertical box Box rightBox = new Box(BoxLayout.Y_AXIS); Box leftBox = new Box(BoxLayout.Y_AXIS); // Monitor all list selections list.addListSelectionListener(new RadioUpdater()); for (int i = 0; i < label.length; i++) { checks[i] = new JCheckBox("Selection " + i); checks[i].setEnabled(false);// w w w . j av a 2s .c o m rightBox.add(checks[i]); } leftBox.add(pane); add(rightBox, BorderLayout.EAST); add(leftBox, BorderLayout.WEST); }
From source file:Main.java
public Main() { setLayout(new BorderLayout()); list = new JList(label); JButton button = new JButton("Print"); JScrollPane pane = new JScrollPane(list); DefaultListSelectionModel m = new DefaultListSelectionModel(); m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); m.setLeadAnchorNotificationEnabled(false); list.setSelectionModel(m);// www .ja va 2 s . co m list.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { System.out.println(e.toString()); } }); button.addActionListener(new PrintListener()); add(pane, BorderLayout.NORTH); add(button, BorderLayout.SOUTH); }
From source file:SimpleList2.java
public SimpleList2() { setLayout(new BorderLayout()); list = new JList(label); JButton button = new JButton("Print"); JScrollPane pane = new JScrollPane(list); DefaultListSelectionModel m = new DefaultListSelectionModel(); m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); m.setLeadAnchorNotificationEnabled(false); list.setSelectionModel(m);/*from w ww . j a v a2 s.c o m*/ list.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { System.out.println(e.toString()); } }); button.addActionListener(new PrintListener()); add(pane, BorderLayout.NORTH); add(button, BorderLayout.SOUTH); }
From source file:Main.java
public Main() { super();//from ww w . j av a 2 s.c o m setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().setLayout(new GridLayout(4, 1)); startButton = makeButton("Start"); stopButton = makeButton("Stop"); stopButton.setEnabled(false); progressBar = makeProgressBar(0, 99); listBox = new JList(listModel); scrollPane.setViewportView(listBox); add(scrollPane); pack(); setVisible(true); }