Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

List layout problem

 
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
I have a bit of a problem. I have a custom component class that consists of JTextBoxes and JButtons in a JPanel and I need to make a visual list of these inside a scroll pane. The components need to have the ability to be added/changed/deleted to the list at run time, and clicks need to be able to reach the buttons inside the components. As for layout, I need each component to only take up the space needed by its internal text/buttons, and be centered at the top left corner (or at the bottom of the previous component).
I have tried using every layout manager, using JList, and using JTable, but I just can't get what I'm looking for.

Thanks for any help,
Chris

Edit:
Design


[ November 27, 2007: Message edited by: Chris Waguespack ]
 
Author
Posts: 976
1
  • 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:
I have tried using every layout manager, using JList, and using JTable, but I just can't get what I'm looking for.



JList and JTable are not layout managers. They are Swing components.

It seems to me you could get most of what you want with a one-column GridLayout. You could approximate your diagram with something like this:

 
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
Thanks for the reply. I realize JTable and JList are not layout managers; I just meant I had tried using their Editors/Renderers until I learned that they were mainly used for text and other simple components only. Your example does exactly what I need except for the fact that if there is only one item, or more specifically if there are not enough components to make the scroll bar appear, it fills up the entire scroll pane. What I would like to have happen is the component only take up the amount of space it needs, and not the entire pane. Does this change need to take place in the scroll pane layout or in the actual component.

Thanks again,
Chris
[ November 28, 2007: Message edited by: Chris Waguespack ]
 
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
I looked into using the Box manager with glue but haven't had much luck. Setting the components' min/max/pref size might work, but I'm worried about what this will do if the look and feel changes (it is set to use the system l&f at the moment.

Thanks,
Chris
 
Brian Cole
Author
Posts: 976
1
  • 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:
Your example does exactly what I need except for the fact that if there is only one item, or more specifically if there are not enough components to make the scroll bar appear, it fills up the entire scroll pane. What I would like to have happen is the component only take up the amount of space it needs, and not the entire pane.



The typical way to handle this is to put the GridLayout panel in the NORTH end of a BorderLayout panel, then put the BorderLayout panel in the scroll pane.
 
What? What, what, what? What what tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic