• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JAVA JList Problem

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I'm struggling again. . .

I have a JList problem because I would want to know how to automatically highlight the DVD/ blu Ray stock in their respective colours (green for DVD, yellow for blu Ray) for that movie title.

I already have the highlighting done in my code.

For a visual image of the assignment, here it is.
URL: http://www.scribd.com/doc/13082448/CSIS1275Assign3w2009

MY PROBLEM IS AT QUESTION 2.

MOVIEBUY.JAVA



MOVIEINFO.JAVA




Thanks for reading, and I hope you can help me on this problem.

- Nathe
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this one's in the JList apidocs

any time you want to change something it is generally a 'set...' method.

you want to change the background color of the selection, so read the docs and see if you can find the matching method.

note: if you have a problem with a component (this time JList), don't post all your code,
just create a simple app, frame with JList (or scrollpane/JList), add a few items of dummy data,
and post that, along with what it is you expect it to do, but doesn't.
 
Nathe Chan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's way too vague. . SIGH.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nathe Chan wrote:That's way too vague. . SIGH.

That's very specific, or would be if you made the effort to follow Michael's suggestions up. You would find the answer in under ½ minute.
 
Nathe Chan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I have so far, but it doesn't make any sense to me. Plus, it doesn't work. Can you give me some guidance?


 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You want to select them all? Then check out methods starting with "add".
 
Nathe Chan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No .. that's not what I said. I want to select a movie from the Movie Titles list and then the program will automatically highlight the DVD/ blu Ray stock in their respective colours(green for DVD, yellow for blu Ray) for that movie title. eek..
 
Nathe Chan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing that the answer has to do with getSelectedIndex() and setSelectedIndex(), but I can't figure it out yet.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
from the look of the 3 JLists in your link, you would need to set all lists selection models the same
i.e. you select the title, which selects (highlights) the DVD and BluRay quantities

next you want the dvd/bluray selection/highlight color to be green for the dvd list and yellow for the bluray list.
the answer to that is very simple, which I gave to you earlier.
there's only 21 set... methods for a JList (aside from inherited), and only 2 of those take color arguments,
so you don't need to be Einstein to figure it out (if at first you're not sure, just try it - it's called experimenting)
 
Nathe Chan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does it go along the lines of?



Oh my goodness, I still don't get it.

- Nathe
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it can be done that way, with listeners, but you would need to add a listener to each list,
in case a quantity was clicked (or make the quantity lists not selectable).

alternative, in setting their selection models the same is only 2 lines of code.
 
Nathe Chan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay .. . I have already added a listener to each list. Then . .?
 
Nathe Chan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Michael Dunn!! ..
I'm so happy now cause' I figured out the solution and had a breakthrough.

For the public who want to understand more of this code, here it is!


 
Nathe Chan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And, yes you would need to add a

addListSelectionListener(this); to it first!
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nathe, there's a better solution than going through each item in the list.

Michael explained it in his previous post:

it can be done that way, with listeners, but you would need to add a listener to each list,
in case a quantity was clicked (or make the quantity lists not selectable).

alternative, in setting their selection models the same is only 2 lines of code.



Assignment instructions if I'm not mistaken is to have the dvdlist and blueray list not selectable.

Since you're using a listener for the movieslist, listbox01.getSelectedIndex() will return the exact index of the movie selected.

See if you can improve that code to 2-3 lines without any loops.
 
reply
    Bookmark Topic Watch Topic
  • New Topic