• Post Reply Bookmark Topic Watch Topic
  • New Topic

List layout problem

 
Chris Waguespack
Ranch Hand
Posts: 36
Eclipse IDE Flex Mac
  • Mark post as helpful
  • send pies
  • 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 ]
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Flex Mac
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Flex Mac
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!