1

Is it possible to set the underline offset when using Font.UNDERLINED? I am using the following to make the font underlined:

LabelField lf = new LabelField("Forgot your password?");
lf.setFont(Font.getDefault().derive(Font.BOLD | Font.UNDERLINED));

The above code produces

enter image description here

I want the underline to appear at the font's bottommost position. Like this:

enter image description here

Solutions I can think of:

  1. One possible solution would be to extend LabelField and override its paint() method. Something in the form:

    paint(Graphics g) {
        super.paint(g);
        g.drawLine(...);
    }
    

    The above code will work fine as long as LabelField's contents will occupy a single line. It will become very messy once the contents will occupy multiple lines. Therefore, I am looking for a more appropriate solution.

  2. Another solution would be to write a new field similar to LabelField from scratch.

tonymontana
  • 5,728
  • 4
  • 34
  • 53
  • Eventually, I ended up writing a custom label fields class. The class doesn't extend `LabelField` and I don't use Font.UNDERLINED in it. In its `paint()` method, I am drawing the underline using `Graphics#drawLine()` method for each and every line of my field. – tonymontana Jun 11 '12 at 12:50

0 Answers0