Add jPanel to jList?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Add jPanel to jList?

  1. #1
    Join Date
    Aug 2011
    Posts
    3

    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?

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    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?
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Aug 2011
    Posts
    3

    Re: Add jPanel to jList?

    Quote Originally Posted by keang View Post
    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

  4. #4
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    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.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  5. #5
    Join Date
    Aug 2011
    Posts
    3

    Re: Add jPanel to jList?

    Quote Originally Posted by keang View Post
    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.

  6. #6
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    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 code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center