Ok, I'm trying to create a JScrollPane that will hold custom visual classes. The way I'm currently doing it is
then when a button is pressed
What I would like to have happen is when I press the button, it will add an instance of the RandomTestBar to the changesPanel, and since the RandomTestBar is bigger than the space I've given to the scroll pane, I would want the scroll bar to appear. Right now, the RandomTestBar is just fitting itself inside the scroll pane. Is this a scroll pane problem or a layout problem, and how would you suggest a fix for this.
Thanks much, Chris
Edit: What I want it to look like
[ February 07, 2008: Message edited by: Chris Waguespack ]
I once had to do something similar, and I ended up using a JList with a custom renderer. One motivation for this is I wanted to be able to drag/drop the panels, so it was handy to use JList's TransferHandler support. But also JList was built to be placed in a JScrollPane and for items to be added/deleted dynamically.
It should be possible to get your approach working (try calling revalidate() not only on the changesPanel but also on the changesScrollPane and see if that helps) but if your RandomTestBar objects are simple enough you might want to consider using a JList.
Ah, ok. That fixes part of my issues. Thanks. So, if I wanted to add a button, or other dynamic component to the bar, would I need to use a table with a custom editor instead? If so, I've tried that but can't seem to get a grasp on the correct way to implement it. Any advise or examples that may be useful?
Joined: Sep 20, 2005
Originally posted by Chris Waguespack: So, if I wanted to add a button, or other dynamic component to the bar, would I need to use a table with a custom editor instead?
JList doesn't have editors at all so, yes, you could use a one-column JTable instead and set a custom cell editor if you want to go with an approach like this. If there components that the user needs to manipulate (perhaps even a single button) I'm not sure this approach is worth it.
Are these test bars related to the panels in this older post of yours? If so I think my advice in that thread is better than my advice in this thread.
Ah! I completely forgot about that. Yes, that one does great, but I need the custom bars to stay a fixed size, so that they will not try to take up the entire viewing area. Setting the minimum/preferred size of the panels doesn't seem to help. Thanks for all of your help and patience.
Ok, I got it this far, but the scroll bars won't update until I resize the window. How do I fix this?
EDIT: Found what was wrong, needed to validate the changesScrollPane instead of the changesScrollPanel. Thanks for your help, I'm finally done [ February 27, 2008: Message edited by: Chris Waguespack ]
Joined: Sep 20, 2005
Originally posted by Chris Waguespack: the scroll bars won't update until I resize the window. How do I fix this?
If the JPanel doesn't realize it needs to change size then its enclosing JScrollPane won't adjust its scroll bars.
It should work if you replace changesScrollPanel.validate() with changesScrollPane.validate(). Or actually, I would instead call changesScrollPane.revalidate() but the result is the same.
[edit: I see you figured this out as I was typing. cool.] [ February 27, 2008: Message edited by: Brian Cole ]