List of usage examples for javax.swing JList JList
public JList()
JList
with an empty, read-only, model. From source file:Main.java
Main(String s) { super(s);/*w w w . j ava 2 s. c o m*/ ListModel lm = new StaticListModel(); JList list = new JList(); list.setModel(lm); list.setCellRenderer(new MyCellRenderer()); getContentPane().add(new JScrollPane(list)); setDefaultCloseOperation(EXIT_ON_CLOSE); }
From source file:InvokeLaterExample.java
public InvokeLaterExample() { JButton button = new JButton(new LongRunningModelFillAction()); add(button);/*from w w w .jav a 2 s. c om*/ JList list = new JList(); this.listModel = new DefaultListModel(); this.listModel.addElement("An Empty List Model"); list.setModel(listModel); add(new JScrollPane(list)); add(new JLabel("Status:")); this.statusArea = new JLabel(); add(this.statusArea); }
From source file:MainClass.java
MainClass(String s) { super(s);//from w ww .j a v a 2 s . c o m ListModel lm = new StaticListModel(); JList list = new JList(); list.setModel(lm); list.setCellRenderer(new MyCellRenderer()); getContentPane().add(new JScrollPane(list)); setDefaultCloseOperation(EXIT_ON_CLOSE); }
From source file:SwingWorkerExample.java
public SwingWorkerExample() { JButton button = new JButton(new LongRunningModelFillAction()); add(button);//from www .ja v a 2 s. c o m JList list = new JList(); this.listModel = new DefaultListModel(); this.listModel.addElement("An Empty List Model"); list.setModel(listModel); add(new JScrollPane(list)); add(new JLabel("Status:")); this.statusArea = new JLabel(); add(this.statusArea); }
From source file:Main.java
public Main() { Container pane = getContentPane(); GroupLayout gl = new GroupLayout(pane); pane.setLayout(gl);/* w ww .j a v a 2s . c o m*/ JLabel avLbl = new JLabel("Available"); JLabel tagsLbl = new JLabel("Tags"); JLabel selLbl = new JLabel("Selected"); JButton newBtn = new JButton("New"); JButton moveBtn = new JButton(">>"); JButton remBtn = new JButton("Remove"); JList leftList = new JList(); JScrollPane spleft = new JScrollPane(leftList); JList rightList = new JList(); JScrollPane spright = new JScrollPane(rightList); gl.setAutoCreateGaps(true); gl.setAutoCreateContainerGaps(true); gl.setHorizontalGroup(gl.createParallelGroup(CENTER).addComponent(tagsLbl) .addGroup(gl.createSequentialGroup() .addGroup(gl.createParallelGroup(CENTER).addComponent(avLbl) .addComponent(spleft, 100, 200, Short.MAX_VALUE).addComponent(newBtn)) .addComponent(moveBtn).addGroup(gl.createParallelGroup(CENTER).addComponent(selLbl) .addComponent(spright, 100, 200, Short.MAX_VALUE).addComponent(remBtn)))); gl.setVerticalGroup(gl.createSequentialGroup().addComponent(tagsLbl) .addGroup(gl.createParallelGroup(CENTER) .addGroup(gl.createSequentialGroup().addComponent(avLbl) .addComponent(spleft, 100, 250, Short.MAX_VALUE).addComponent(newBtn)) .addComponent(moveBtn).addGroup(gl.createSequentialGroup().addComponent(selLbl) .addComponent(spright, 100, 250, Short.MAX_VALUE).addComponent(remBtn)))); pack(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:net.sf.maltcms.chromaui.charts.GradientPaintScale.java
/** * * @param args// ww w. ja v a2 s .co m */ public static void main(String[] args) { double[] st = ImageTools.createSampleTable(256); Logger.getLogger(GradientPaintScale.class.getName()).info(Arrays.toString(st)); double min = 564.648; double max = 24334.234; GradientPaintScale gps = new GradientPaintScale(st, min, max, new Color[] { Color.BLACK, Color.RED, Color.orange, Color.yellow, Color.white }); double val = min; double incr = (max - min) / (st.length - 1); Logger.getLogger(GradientPaintScale.class.getName()).log(Level.INFO, "Increment: {0}", incr); for (int i = 0; i < st.length; i++) { Logger.getLogger(GradientPaintScale.class.getName()).log(Level.INFO, "Value: {0}", val); gps.getPaint(val); val += incr; } Logger.getLogger(GradientPaintScale.class.getName()).info("Printing min and max values"); Logger.getLogger(GradientPaintScale.class.getName()).log(Level.INFO, "Min: {0} gps min: {1}", new Object[] { min, gps.getPaint(min) }); Logger.getLogger(GradientPaintScale.class.getName()).log(Level.INFO, "Max: {0} gps max: {1}", new Object[] { max, gps.getPaint(max) }); JList jl = new JList(); DefaultListModel dlm = new DefaultListModel(); jl.setModel(dlm); jl.setCellRenderer(new ListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value instanceof JLabel) { // Border b = // BorderFactory.createCompoundBorder(BorderFactory // .createEmptyBorder(0, 0, 5, 0), BorderFactory // .createLineBorder(Color.BLACK, 1)); // ((JLabel) value).setBorder(b); return (Component) value; } return new JLabel(value.toString()); } }); JFrame jf = new JFrame(); jf.add(new JScrollPane(jl)); jf.setVisible(true); jf.setSize(200, 400); for (int alpha = -10; alpha <= 10; alpha++) { for (int beta = 1; beta <= 20; beta++) { gps.setAlphaBeta(alpha, beta); // System.out.println(Arrays.toString(gps.st)); // System.out.println(Arrays.toString(gps.sampleTable)); BufferedImage bi = gps.getLookupImage(); ImageIcon ii = new ImageIcon(bi); dlm.addElement(new JLabel(ii)); } } }
From source file:Main.java
public static JList generateListFor(Object... objs) { Container c = search(objs, Container.class); String[] name_value = search(objs, String[].class); ListModel model = search(objs, ListModel.class); Object[] dataObjects = search(objs, Object[].class); Vector dataVector = search(objs, Vector.class); ListSelectionListener selectionListener = search(objs, ListSelectionListener.class); ListUI ui = search(objs, ListUI.class); ListSelectionModel selectionModel = search(objs, ListSelectionModel.class); ListCellRenderer cellRenderer = search(objs, ListCellRenderer.class); JList list = model == null// w w w. ja va2s . com ? (dataObjects == null ? (dataVector == null ? new JList() : new JList(dataVector)) : new JList(dataObjects)) : new JList(model); list.setName(name_value == null ? "" : name_value[0]); if (selectionListener != null) list.addListSelectionListener(selectionListener); if (ui != null) list.setUI(ui); if (selectionModel != null) list.setSelectionModel(selectionModel); if (cellRenderer != null) list.setCellRenderer(cellRenderer); addJContainerListeners(list, objs); if (c != null) addToContainer(c, list); return list; }
From source file:Main.java
private void removeActionPerformed(ActionEvent e) { System.out.println("made_list's model: " + made_list.getModel()); System.out.println("Model from a fresh JList: " + new JList().getModel()); DefaultListModel model = (DefaultListModel) made_list.getModel(); if (model.size() > 0) { model.remove(0);/*from w ww. j av a 2 s .com*/ } }
From source file:AppletJDBCDrop.java
public void init() { Connection connection;/* w w w. j a va2 s. c o m*/ try { Class.forName("com.mysql.jdbc.Driver").newInstance(); connection = DriverManager .getConnection("jdbc:mysql://192.168.1.25/accounts?user=spider&password=spider"); } catch (Exception connectException) { connectException.printStackTrace(); } Container c = getContentPane(); tableList = new JList(); loadTables(); c.add(new JScrollPane(tableList), BorderLayout.NORTH); dropButton = new JButton("Drop Table"); dropButton.addActionListener(this); c.add(dropButton, BorderLayout.SOUTH); }
From source file:brainflow.core.ImageBrowser.java
private void initSourceView() { sourceView = new JList(); final DefaultListModel model = new DefaultListModel(); for (IImageSource source : sourceList.sourceList) { model.addElement(source);/*from www . j a va 2 s .com*/ } sourceView.setModel(model); sourceView.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ButtonPanel panel = new ButtonPanel(SwingConstants.CENTER); JButton nextButton = new JButton("Next"); ImageIcon icon = new ImageIcon(getClass().getClassLoader().getResource("icons/control_play_blue.png")); nextButton.setIcon(icon); JButton prevButton = new JButton("Previous"); icon = new ImageIcon(getClass().getClassLoader().getResource("icons/control_rev_blue.png")); prevButton.setIcon(icon); panel.addButton(prevButton); panel.addButton(nextButton); panel.setSizeConstraint(ButtonPanel.SAME_SIZE); JPanel container = new JPanel(new BorderLayout()); container.setBorder(new TitledBorder("Image List")); container.add(new JScrollPane(sourceView), BorderLayout.CENTER); container.add(panel, BorderLayout.SOUTH); add(container, BorderLayout.WEST); nextButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int index = sourceView.getSelectedIndex(); if (index == (sourceList.size() - 1)) { index = 0; } else { index++; } updateView(index); } }); sourceView.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int index = sourceView.getSelectedIndex(); if (currentModel.getSelectedLayer().getDataSource() != sourceView.getSelectedValue()) { System.out.println("updating view"); updateView(index); } else { System.out.println("not updating view "); } } }); }