Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

JScrollPane Frustrations

 
Ranch Hand
Posts: 36
Mac Eclipse IDE Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Brian Cole
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To show what I mean, here's some code that approximates the look of your diagram.

 
Chris Waguespack
Ranch Hand
Posts: 36
Mac Eclipse IDE Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

Thanks,
Chris
 
Brian Cole
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Chris Waguespack
Ranch Hand
Posts: 36
Mac Eclipse IDE Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

-Chris
 
Chris Waguespack
Ranch Hand
Posts: 36
Mac Eclipse IDE Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I got it this far, but the scroll bars won't update until I resize the window. How do I fix this?



Thanks,
Chris

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 ]
 
Brian Cole
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic