using netbeans gui editor to create a bowling program for school. Is it possible for me to add a jpanel to a jlist? if so how?
Printable View
using netbeans gui editor to create a bowling program for school. Is it possible for me to add a jpanel to a jlist? if so how?
Are you sure you want to add a JPanel to a JList and if so do you mean as an item in the list or as a means of drawing something on the list?
Can you explain exactly what you are you trying to do?
If you have a panel that shows all the scores then why put it in a JList, why not just add it to your GUI?
If you want to show all the players scores in a JList then add each individual name and score to the list as a series of values to display.
Ok, it that case you need to use a custom cell renderer.
You can't add the JPanel to the JList as by default a JList calls the items toString() method to get the information to display but what you can do is provide your own cell renderer that creates the JPanel layout for each item of information in the JLIst. You would then need to add an object containing the information to place in the JPanel for each player. The JList will pass this object to your cell renderer which can interrogate the object and create an appropriate panel which it passes back to the JList. The JList uses the component passed back to draw the details on the screen.