-
August 18th, 2011, 08:39 AM
#1
Add jPanel to jList?
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?
-
August 18th, 2011, 08:49 AM
#2
Re: Add jPanel to jList?
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?
-
August 18th, 2011, 08:54 AM
#3
Re: Add jPanel to jList?
Originally Posted by keang
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?
I have a jpanel that shows the score of each player and I want to show this in a jlist so the user can view all the different player scores. Sorry quite new at this
-
August 18th, 2011, 08:59 AM
#4
Re: Add jPanel to jList?
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.
-
August 18th, 2011, 09:01 AM
#5
Re: Add jPanel to jList?
Originally Posted by keang
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.
No one panel for each player. And the jpanel has a specific layout that I cant get by simply adding values.
-
August 18th, 2011, 09:12 AM
#6
Re: Add jPanel to jList?
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|