File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Update JScrollPane content (JList) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Update JScrollPane content (JList) " Watch "Update JScrollPane content (JList) " New topic

Update JScrollPane content (JList)

Andres Del Pino

Joined: Apr 21, 2010
Posts: 8
Hi, i´m having a problem doing this, i´ve been searching but didn´t find something useful so i ask you...

I have some JScrollPane and when someone click a button i want to change the contents of the JScrollPane

Here comes some code:

And when i click the button i do this:

But this seems to do nothing, any help? <-- UPDATE
In fact it does something, internally it seems to have changed, but I still see the same info. For example...
I have a JScrollPane and it shows elements 4 5 and 6, when i press the button it should only show 5 but i still see 4, 5 and 6, but when i click any of them it has element 5 info like it has really changed but i need to see only 5 in the JScrollPane
This is an applet, but that doesn´t change anything, right?
Thank you
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10824

I have a bit of a trouble understanding the code because of the non english names

If you want to update the data in the JList use JList#setListData
If you want to show/hide the JLists (embedded inside the JScrollPane) always invoke JPanel#revalidate and JPanel#repaint after you finish adding/removing

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Andres Del Pino

Joined: Apr 21, 2010
Posts: 8
Sorry the code was in spanish, I translated it so you can understand it better.

I solved it, the problem was the JPanel#revalidate, i wasn´t doing it, so, thank you Maneesh.

I´ll post the final code for people with the same problem:

Thanks for the help.
I agree. Here's the link:
subject: Update JScrollPane content (JList)
It's not a secret anymore!