List of usage examples for javax.swing JList setCellRenderer
@BeanProperty(visualUpdate = true, description = "The component used to draw the cells.") public void setCellRenderer(ListCellRenderer<? super E> cellRenderer)
From source file:fr.duminy.jbackup.swing.ConfigurationManagerPanel.java
private static JList<BackupConfiguration> createList(ConfigurationManager manager) { //TODO enable sorting : JList list = new JList(new SortedListModel(new DefaultListModel(), COMPARATOR)); JList<BackupConfiguration> list = new JList<>(new Model(manager)); list.setCellRenderer(BackupConfigurationRenderer.INSTANCE); list.setName("configurations"); return list;//from w w w. j a v a 2s . co m }
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 ? (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);//from w ww . j av a2 s . c o m 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:eu.europa.ec.markt.dss.applet.util.ComponentFactory.java
/** * /* w ww.j av a2s .c o m*/ * @param name * @param model * @param cellRenderer * @return */ public static JList list(final String name, final ListModel model, final ListCellRenderer cellRenderer) { final JList list = new JList(); list.setName(name); list.setModel(model); if (cellRenderer != null) { list.setCellRenderer(cellRenderer); } return list; }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList<String> list = new JList<>(new String[] { "1", "2", "3" }); list.setCellRenderer(getRenderer()); add(list);//from ww w.j av a2s . com pack(); setVisible(true); }
From source file:Main.java
Main(String s) { super(s);//from w ww . ja v a 2s. 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:MainClass.java
MainClass(String s) { super(s);/* w w w .j ava 2 s. c om*/ 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:ListIt.java
public ListIt() { JFrame f = new JFrame(); final PartsListModel pcm = new PartsListModel(); ListCellRenderer lcr = new MyLabelRenderer(); JList jl = new JList(pcm); jl.setCellRenderer(lcr); ListSelectionModel lsm = jl.getSelectionModel(); lsm.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jl.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { String element[] = (String[]) pcm.getElementAt(e.getFirstIndex()); System.out.println(element[0] + " : " + element[1] + " : " + element[2]); }// w ww . j av a2 s. c o m } }); JScrollPane jsp = new JScrollPane(jl); JComboBox jc = new JComboBox(pcm); jc.setRenderer(lcr); JButton jb = new JButton("Add Merchandise"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { pcm.addElement(partsList[(int) (Math.random() * partsList.length)]); } }); Container c = f.getContentPane(); c.add(jsp, BorderLayout.NORTH); c.add(jc, BorderLayout.CENTER); c.add(jb, BorderLayout.SOUTH); f.setSize(250, 250); f.show(); }
From source file:Main.java
public ListRenderingFrame() { setTitle("ListRendering"); setSize(400, 300);//from ww w.ja va2 s . c om addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); Vector fonts = new Vector(); fonts.add(new Font("Serif", Font.PLAIN, 8)); fonts.add(new Font("SansSerif", Font.BOLD, 12)); fonts.add(new Font("Monospaced", Font.PLAIN, 16)); fonts.add(new Font("Dialog", Font.ITALIC, 12)); fonts.add(new Font("DialogInput", Font.PLAIN, 12)); JList fontList = new JList(fonts); fontList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fontList.setCellRenderer(new FontCellRenderer()); JScrollPane scrollPane = new JScrollPane(fontList); JPanel p = new JPanel(); p.add(scrollPane); fontList.addListSelectionListener(this); getContentPane().add(p, "Center"); getContentPane().add(label, "South"); }
From source file:fr.duminy.jbackup.swing.SourceListTypeMapper.java
@Nonnull @Override/*w ww . j a v a 2 s .c om*/ public ListPanel<Source, JList<Source>> createEditorComponent() { JList<Source> list = new JList(new DefaultMutableListModel<Source>()); list.setName("sources"); list.setCellRenderer(SourceRenderer.INSTANCE); DefaultFormBuilder sourceFormBuilder = new DefaultFormBuilder<Source>(Source.class) { @Override protected void configureBuilder(FormBuilder<Source> builder) { super.configureBuilder(builder); builder.useForProperty("path", new StringPathTypeMapper(SHOW_HIDDEN_FILES_BUILDER)); } }; SimpleItemManager<Source> sourceProvider = new SimpleItemManager<>(Source.class, sourceFormBuilder, parent, "Source", DIALOG); return new SourceListPanel(list, sourceProvider); }
From source file:com.frostwire.gui.library.LibraryFilesTableMediator.java
/** * Creates a JList of files and sets and makes it non-selectable. *///from w ww. j a v a 2 s. c om 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; }