aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Line spacing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Line spacing" Watch "Line spacing" New topic
Author

Line spacing

Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
Hi, my first newbie question. I did search and could not find an answer elsewhere. I am creating a small application at work as part of a learning experience in Java, a simple How-To manual for our newbies. At this point I am trying to get the banner to look right, and have made some progress. Where I am currently stuck is in spacing the lines, I need to get them close together than the app is currently doing. The lines in question are in the banner section; I need to cut the spacing by half, while leaving the font sizes as they are.

Thanks in advance,

Mike

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11404
    
  16

This looks more like a Swing/AWT type question. You'll probably get a better response there, so i'll move it over for you.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Looks like you have the components compressed as much as possible in the vertical
dimension in your GridLayout.
To reduce the space further you could try two things.
One is to reduce the preferredSize.height of the labels.
Another is to use different layouts. One of the difficulties with using GridLayout is that
it doesn't pay much attention to the preferredSize of each of the components but tries to
divide the available space into a grid of equal size cells. Using a layout manager that
respects the preferredSize of its (containers) child components can help reduce the space
used for display. FlowLayout and GridBagLayout are two layout managers that try to show
every child component at its preferredSize.
Testing indicates that the first option might be more effective than the second.
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Originally posted by Mike Lipay:
Where I am currently stuck is in spacing the lines, I need to get them close together than the app is currently doing. The lines in question are in the banner section; I need to cut the spacing by half, while leaving the font sizes as they are.


I'm not sure exactly what your code is doing when it uses the same layoutTF instance in multiple containers but tries to setVgap() differently for each. I don't think that has anything to do with your spacing problem, though.

One problem is that your row1 and row2 panels default to having a 5-pixel border. You can get rid of this by replacing new JPanel() with new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0).

Another problem is just that JLabels return a preferred size that is larger than you want. You can easily set a preferred size that is shorter. Here's some code demonstrating way to do this. The shorter preferred size is set in the squish() method. (This code doesn't use row1/row2, so their 5-pixel borders don't come into play.)



This code also changes your setHorizontalAlignment(0) calls to setHorizontalAlignment(JLabel.CENTER). It works out the same but makes it easier to understand what it is doing.

[edit: Mention that code doesn't use row1/row2.]
[ September 12, 2007: Message edited by: Brian Cole ]

bitguru blog
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
Thanks. I tried changing the preferredSize, but nothing happened. Flow layout doesn't work well because it fits more on a line than I really want there, the desired layout is very specific and more important than the distance between the lines. Just would have been nice to give them exactly what they wanted on my first project.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Line spacing