This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes superscript and underline at the same time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "superscript and underline at the same time" Watch "superscript and underline at the same time" New topic
Author

superscript and underline at the same time

Michelle Kyamo
Greenhorn

Joined: Aug 25, 2009
Posts: 18
I have a StyledDocument where I want one whole line to be underlined, and a few characters in the line are also in superscript. What happens is that the underline that runs under the superscripted characters is raised compared to the underline under the regular characters. I want the underline to be continuous under the whole line. Is there a way to fix this?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
Too difficult a question for us beginners. Moving thread.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I don't know but I'm going to speculate.

What you are seeing is superscripted underlined characters. (Which is something that I have seen in print.) What you want to see is underlined superscripted characters. (I haven't seen that in print but it seems like a reasonable thing to want.) Perhaps the order in which you set up the styling makes a difference? Perhaps not, that's just a guess.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

If all else fails, you could try applying the UNDERLINE_LOW_ONE_PIXEL / UNDERLINE_LOW_TWO_PIXEL attribute to the superscripted text.


luck, db
There are no new questions, but there may be new answers.
Michelle Kyamo
Greenhorn

Joined: Aug 25, 2009
Posts: 18
Paul Clapham wrote:I don't know but I'm going to speculate.

What you are seeing is superscripted underlined characters. (Which is something that I have seen in print.) What you want to see is underlined superscripted characters. (I haven't seen that in print but it seems like a reasonable thing to want.) Perhaps the order in which you set up the styling makes a difference? Perhaps not, that's just a guess.


Thanks for the idea, but the switching the order didn't change anything.
Michelle Kyamo
Greenhorn

Joined: Aug 25, 2009
Posts: 18
Darryl Burke wrote:If all else fails, you could try applying the UNDERLINE_LOW_ONE_PIXEL / UNDERLINE_LOW_TWO_PIXEL attribute to the superscripted text.


Trying to do this but it doesn't seem to be working (I mean I can't seem to apply the attribute at all, not that it doesn't fix my problem).

doc2 = textpane2.getStyledDocument();
superscript = doc2.addStyle("superscript",null);
StyleConstants.setSuperscript(superscript,true);
undersuper = doc2.addStyle("undersuper", superscript);
undersuper.addAttribute(TextAttribute.UNDERLINE,TextAttribute.UNDERLINE_LOW_TWO_PIXEL);

I then use undersuper in the insertString method of StyledDocument (have also tried setCharacterAttributes) and the text appears superscripted with no underline.
Michelle Kyamo
Greenhorn

Joined: Aug 25, 2009
Posts: 18
It seems I can only make the attributes in StyleConstants work, not anything in TextAttribute.

I reduced the font size of the superscript a little, which makes the problem a little less (the underlines are offset still, but less so).
Michelle Kyamo
Greenhorn

Joined: Aug 25, 2009
Posts: 18
Michelle Kyamo wrote:It seems I can only make the attributes in StyleConstants work, not anything in TextAttribute.

I reduced the font size of the superscript a little, which makes the problem a little less (the underlines are offset still, but less so).


Does anyone know how to make the TextAttribute work so I can use UNDERLINE_LOW_ONE_PIXEL?
 
 
subject: superscript and underline at the same time
 
Similar Threads
Hello with underline
Super and sub string in java to string
Subscript & Superscript Question
representing exponents like x to the power 2 3 and so on
Reading super script in Apache POI