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:Main.java
public static void main(String[] args) { String[] names = { "John Smith", "this is a test", "this is a test. this is a test. " }; MyCellRenderer cellRenderer = new MyCellRenderer(80); JList<String> list = new JList<>(names); list.setCellRenderer(cellRenderer); JScrollPane sPane = new JScrollPane(list); JPanel panel = new JPanel(); panel.add(sPane);//ww w . j a v a 2 s . c om JOptionPane.showMessageDialog(null, panel); }
From source file:MyCellRenderer.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList list = new JList(new String[] { "A", "B", "C" }); list.setCellRenderer(new MyCellRenderer()); frame.add(new JScrollPane(list)); frame.setSize(300, 200);// w w w.j a va 2 s . c om frame.setVisible(true); }
From source file:CustomBorderSample.java
public static void main(String args[]) { String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; JFrame frame = new JFrame("Custom Border"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JList jlist = new JList(labels); ListCellRenderer renderer = new FocusedTitleListCellRenderer(); jlist.setCellRenderer(renderer); JScrollPane sp = new JScrollPane(jlist); contentPane.add(sp, BorderLayout.CENTER); frame.setSize(300, 200);/*from w ww. j a v a 2s .c o m*/ frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { Object elements[][] = { { new Font("Courier", Font.BOLD, 16), Color.YELLOW, "This" }, { new Font("Helvetica", Font.ITALIC, 8), Color.DARK_GRAY, "Computer" } }; JFrame frame = new JFrame("Complex Renderer"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList jlist = new JList(elements); ListCellRenderer renderer = new ComplexCellRenderer(); jlist.setCellRenderer(renderer); JScrollPane scrollPane = new JScrollPane(jlist); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 200);/*from w w w . java 2s . co m*/ frame.setVisible(true); }
From source file:SizingSamples.java
public static void main(String args[]) { JFrame frame = new JFrame("Sizing Samples"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultListModel model = new DefaultListModel(); model.ensureCapacity(100);/*from w w w . j av a 2 s .c o m*/ for (int i = 0; i < 100; i++) { model.addElement(Integer.toString(i)); } JList jlist2 = new JList(model); ListCellRenderer renderer = new FocusedTitleListCellRenderer(); jlist2.setCellRenderer(renderer); JScrollPane scrollPane2 = new JScrollPane(jlist2); frame.add(scrollPane2, BorderLayout.CENTER); frame.setSize(300, 350); frame.setVisible(true); jlist2.ensureIndexIsVisible(50); }
From source file:ComplexCellRenderer.java
public static void main(String args[]) { Object elements[][] = { { new Font("Helvetica", Font.PLAIN, 20), Color.RED, new MyIcon(), "A" }, { new Font("TimesRoman", Font.BOLD, 14), Color.BLUE, new MyIcon(), "A" }, { new Font("Courier", Font.ITALIC, 18), Color.GREEN, new MyIcon(), "A" }, { new Font("Helvetica", Font.BOLD | Font.ITALIC, 12), Color.GRAY, new MyIcon(), "A" }, { new Font("TimesRoman", Font.PLAIN, 32), Color.PINK, new MyIcon(), "A" }, { new Font("Courier", Font.BOLD, 16), Color.YELLOW, new MyIcon(), "A" }, { new Font("Helvetica", Font.ITALIC, 8), Color.DARK_GRAY, new MyIcon(), "A" } }; JFrame frame = new JFrame("Complex Renderer"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList jlist = new JList(elements); ListCellRenderer renderer = new ComplexCellRenderer(); jlist.setCellRenderer(renderer); JScrollPane scrollPane = new JScrollPane(jlist); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 200);/* w w w. j a v a 2 s . c om*/ frame.setVisible(true); }
From source file:ComplexRenderingSample.java
public static void main(String args[]) { Object elements[][] = {//from ww w. ja v a 2s .com { new Font("Helvetica", Font.PLAIN, 20), Color.red, new DiamondIcon(Color.blue), "Help" }, { new Font("TimesRoman", Font.BOLD, 14), Color.blue, new DiamondIcon(Color.green), "Me" }, { new Font("Courier", Font.ITALIC, 18), Color.green, new DiamondIcon(Color.black), "I'm" }, { new Font("Helvetica", Font.BOLD | Font.ITALIC, 12), Color.gray, new DiamondIcon(Color.magenta), "Trapped" }, { new Font("TimesRoman", Font.PLAIN, 32), Color.pink, new DiamondIcon(Color.yellow), "Inside" }, { new Font("Courier", Font.BOLD, 16), Color.yellow, new DiamondIcon(Color.red), "This" }, { new Font("Helvetica", Font.ITALIC, 8), Color.darkGray, new DiamondIcon(Color.pink), "Computer" } }; JFrame frame = new JFrame("Complex Renderer"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JList jlist = new JList(elements); ListCellRenderer renderer = new ComplexCellRenderer(); jlist.setCellRenderer(renderer); JScrollPane scrollPane = new JScrollPane(jlist); contentPane.add(scrollPane, BorderLayout.CENTER); JComboBox comboBox = new JComboBox(elements); comboBox.setRenderer(renderer); contentPane.add(comboBox, BorderLayout.NORTH); frame.setSize(300, 300); frame.setVisible(true); }
From source file:com.googlecode.sarasvati.visual.jung.JungVisualizer.java
@SuppressWarnings("serial") public static void main(String[] args) throws Exception { TestSetup.init();/*w w w .j a va2 s . co m*/ Session session = TestSetup.openSession(); HibEngine engine = new HibEngine(session); JFrame frame = new JFrame("Workflow Visualizer"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setMinimumSize(new Dimension(800, 600)); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); frame.getContentPane().add(splitPane); DefaultListModel listModel = new DefaultListModel(); for (Graph g : engine.getRepository().getGraphs()) { listModel.addElement(g); } ListCellRenderer cellRenderer = new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); Graph g = (Graph) value; setText(g.getName() + "." + g.getVersion() + " "); return this; } }; final JList graphList = new JList(listModel); graphList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); graphList.setCellRenderer(cellRenderer); JScrollPane listScrollPane = new JScrollPane(graphList); listScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); listScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); splitPane.add(listScrollPane); //TreeLayout<NodeRef, Arc> layout = new TreeLayout<NodeRef, Arc>(); DirectedSparseMultigraph<Node, Arc> graph = new DirectedSparseMultigraph<Node, Arc>(); //final SpringLayout2<HibNodeRef, HibArc> layout = new SpringLayout2<HibNodeRef, HibArc>(graph); //final KKLayout<HibNodeRef, HibArc> layout = new KKLayout<HibNodeRef, HibArc>(graph); final TreeLayout layout = new TreeLayout(graph); final BasicVisualizationServer<Node, Arc> vs = new BasicVisualizationServer<Node, Arc>(layout); //vs.getRenderContext().setVertexLabelTransformer( new NodeLabeller() ); //vs.getRenderContext().setEdgeLabelTransformer( new ArcLabeller() ); vs.getRenderContext().setVertexShapeTransformer(new NodeShapeTransformer()); vs.getRenderContext().setVertexFillPaintTransformer(new NodeColorTransformer()); vs.getRenderContext().setLabelOffset(5); vs.getRenderContext().setVertexIconTransformer(new Transformer<Node, Icon>() { @Override public Icon transform(Node node) { return "task".equals(node.getType()) ? new TaskIcon(node) : null; } }); Transformer<Arc, Paint> edgeColorTrans = new Transformer<Arc, Paint>() { private Color darkRed = new Color(128, 0, 0); @Override public Paint transform(Arc arc) { return "reject".equals(arc.getName()) ? darkRed : Color.black; } }; vs.getRenderContext().setEdgeDrawPaintTransformer(edgeColorTrans); vs.getRenderContext().setArrowDrawPaintTransformer(edgeColorTrans); final JScrollPane scrollPane = new JScrollPane(vs); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); splitPane.add(scrollPane); scrollPane.setBackground(Color.white); graphList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } final Graph g = (Graph) graphList.getSelectedValue(); if ((g == null && currentGraph == null) || (g != null && g.equals(currentGraph))) { return; } currentGraph = g; DirectedSparseMultigraph<Node, Arc> jungGraph = new DirectedSparseMultigraph<Node, Arc>(); for (Node ref : currentGraph.getNodes()) { jungGraph.addVertex(ref); } for (Arc arc : currentGraph.getArcs()) { jungGraph.addEdge(arc, arc.getStartNode(), arc.getEndNode()); } GraphTree graphTree = new GraphTree(g); layout.setGraph(jungGraph); layout.setInitializer(new NodeLocationTransformer(graphTree)); scrollPane.repaint(); } }); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList list = new JList(new CheckListItem[] { new CheckListItem("apple"), new CheckListItem("orange"), new CheckListItem("mango"), new CheckListItem("mango"), new CheckListItem("mango"), new CheckListItem("mango"), new CheckListItem("mango"), new CheckListItem("mango"), new CheckListItem("mango"), new CheckListItem("mango"), new CheckListItem("mango"), new CheckListItem("paw paw"), new CheckListItem("banana") }); list.setCellRenderer(new CheckListRenderer()); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.addMouseListener(new MouseAdapter() { @Override/*from w ww . ja va 2 s. c o m*/ public void mouseClicked(MouseEvent event) { JList list = (JList) event.getSource(); int index = list.locationToIndex(event.getPoint());// Get index of item // clicked CheckListItem item = (CheckListItem) list.getModel().getElementAt(index); item.setSelected(!item.isSelected()); // Toggle selected state list.repaint(list.getCellBounds(index, index));// Repaint cell } }); frame.getContentPane().add(new JScrollPane(list)); frame.pack(); frame.setVisible(true); }
From source file:net.sf.maltcms.chromaui.charts.GradientPaintScale.java
/** * * @param args/* w ww . ja v a 2 s . c om*/ */ 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)); } } }