Name: ssT124754 Date: 02/01/2001
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
Trying to use a 'javax.swing.border.TitledBorder' to outline my JComponents, I
noticed a significant vertical gap always appearing below the text of the title
of the TitledBorder and above the object it outlined. This eats into the
vertical real estate I have available for my apps. For example, in the code
fragment (to be put in some applet's init() method)
JTextPane textPane = new JTextPane();
JScrollPane scrollPane = new JScrollPane(textPane);
scrollPane.setPreferredSize(new Dimension(((Applet) this).getSize().width -
JPanel somePane = new JPanel(false);
you'll see that the title "Instructions" has a substantial gap below it but
before the JScrollPane. I looked through the source of TitledBorder and found
the problem in the 'getBorderInsets(Component, Insets)' method.
There is a switch statement 'switch(getTitlePosition())' that has
a case statement matching 'TOP' that has the following body:
insets.top += ascent + descent;
and I believe it should read...
insets.top += (ascent / 2) + descent;
since the title is vertically centered in the border. The same holds for the
'BOTTOM' case statement of that switch.
After developing my workaround, I wondered if it would simply be possible to
create some accessor methods so that the user could pad the space with pixels
to increase or decrease this buffer zone (and other buffers used throughout the
class) on an individual basis. Something like
insets.top += (ascent / 2) + descent + this.getInternalTopPadding();
(Review ID: 115872)