Question

I have a custom renderer that works just perfectly - how can I use it as a "drawing engine" to produce the same objects it would produce in a JList?

Was it helpful?

Solution 2

If you have a ListCellRenderer, simply invoke getListCellRendererComponent() with the appropriate values, and then invoke setBounds(x, y, w, h) and paint(g) on the returned component (which is all normal cases is the renderer itself) to paint it as it would be in a list.

OTHER TIPS

how can I use it as a "drawing engine" to produce the same objects it would produce in a JList?

AFAIK

  • Renderer is only illusion, painting factory betweens value stored in XxxModel and View

  • Renderer is implemented for JList (then for JComboBox too), JTree and JTable (now we can forgot for JTreeTable and its custom derivates)

  • for rest of Swing JComponents you have to use standard paint, more informations, wroking code examples in official Oracle tutorials

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top