Thanks, will try it right away. I didn't know about
the SwingUtilities.layoutCompoundLabel(). I'm still
hoping there is a tricky Unicode or Font solution!
--- Neil Thorne <[EMAIL PROTECTED]> wrote:
> I found some code on the Sun Forum for underlining
> the text in a JLabel.
> Basically, it overrides the paint method to extend
> what it paints to include
> a fairly crude thin rectangle underneath the text,
> which looks suprisingly
> good:
>
> Here's the code which works for JLabels. Maybe you
> can extend it for other
> components, I haven't really tried...
>
> public void paint(Graphics g)
>
> {
> super.paint(g);
> graphics = g;
> if(underlined)
> underlineText(g);
> }
>
> protected void underlineText(Graphics g)
> {
> Insets i = getInsets();
> FontMetrics fm = g.getFontMetrics();
>
> Rectangle textRect = new Rectangle();
> Rectangle viewRect = new Rectangle(i.left, i.top,
> getWidth()
> - (i.right + i.left), getHeight() - (i.bottom +
> i.top) );
>
> String text = SwingUtilities.layoutCompoundLabel
> (
> this, fm, getText(), getIcon(),
> getVerticalAlignment(), getHorizontalAlignment(),
> getVerticalTextPosition(),
> getHorizontalTextPosition(), viewRect, new
> Rectangle(), textRect,
> getText() == null ? 0 :
>
((Integer)UIManager.get("Button.textIconGap")).intValue()
> );
>
> g.fillRect
> (
> textRect.x +
>
((Integer)UIManager.get("Button.textShiftOffset")).intValue()
> -4,
> textRect.y + fm.getAscent() +
>
((Integer)UIManager.get("Button.textShiftOffset")).intValue()
> + 2,
> textRect.width, 1
> );
> }
>
> regards,
>
> Neil
>
> -----Original Message-----
> From: Steve Barrett [mailto:[EMAIL PROTECTED]]
> Sent: 01 February 2001 04:05
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: non html Underline technique?
>
>
> I am using JButtons, TableCellRenderers and JLabels
> all of which need underlined text. I have
> subclassed
> to override paint to get underlines. I have tried
> HTML strings and used borders. None of which are
> great all around solutions. For instance HTML is
> too
> slow for renderers, overriding paint duplicates a
> ton
> of code (alignment, string positioning, icon
> positioning, etc), borders don't line up with the
> text, etc. Isn't there a better way, this seems
> like
> such an obvious thing?
>
> __________________________________________________
> Get personalized email addresses from Yahoo! Mail -
> only $35
> a year! http://personal.mail.yahoo.com/
> _______________________________________________
> Advanced-swing mailing list
> [EMAIL PROTECTED]
> http://eos.dk/mailman/listinfo/advanced-swing
>
>
>
**********************************************************************
> This email is intended only for the addressee. This
> email
> and any files transmitted with it may contain
> confidential
> or privileged information. If you are not the named
> addressee or the person responsible for delivering
> the
> message to the named addressee, please contact
> [EMAIL PROTECTED]
>
> This email has been scanned by MAILsweeper.
>
**********************************************************************
__________________________________________________
Get personalized email addresses from Yahoo! Mail - only $35
a year! http://personal.mail.yahoo.com/
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing