• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Access JLabel text in JPanel in JList

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi guys

i have a JList that i have rendered with a JLabel and Icon set it on a panel and put that into an array into a JList...

all works great but is there a way to get the text in the JLabel i have created???




the renderer


i want to get the text from the new list selected item...

many thanks
 
peter hammond
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ended up doing it a dirty way by created another array to log what was selected in the first list..

but would still like to know if its possible to access a label from jpanels in a list........
 
Marshal
Posts: 25956
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isn't even easy to get a JLabel from a JPanel. But why should it be easy? JPanel wasn't designed as a container for a JLabel, so there is little reason for JPanel to provide an obvious method to get a JLabel out of it. There are unobvious methods, though, but I recommend doing what you did.

Although really I recommend reviewing why you decided you needed the JPanel. I don't see a need for it, but perhaps you found that something didn't come out right if you just just used a JLabel by itself?

Actually you don't even need to use a JLabel, since your cell renderer already is (or can be) a JLabel. All your renderer code needs to do is to set the colours of the renderer appropriately.
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If you can post a working code; then we can help.

 
peter hammond
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah i did think about ditching the panels and just labeling up the listed items but i found it was cleaner to package everything up in its individual panel then add all the panels to the list then access those panles from a master array and sub array...

it all works fine it was a question really to find out if it was possible to access these labels from within panels which i know now you cant so in future projects i will know to think of another way to display the items...

thanks for you guys help i have learnt so much here already as there are people that do reply to post

hopefully in time maybe i can help people out once i get enough practise in....
 
I can't take it! You are too smart for me! Here is the tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic