How can I use a custom JList renderer's results outside of a JList?

93 views Asked by At

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?

2

There are 2 answers

0
Harald K On BEST ANSWER

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.

4
mKorbel On

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