Forums Register Login
Super, subscript with JLabel

Is there anyway to use superscript and subscript with a JLabel combining bold , italic etc. I do not wish to use HTML because the JLabel is in a cell in a Jtable and the user sees the text when he/she edits it.

What is the best approach? The JTable is used for a user to add , edit data that will be used in a catalouge. Every cell can

* Edit alignment
* bold
* Italic
* Underline
* subscript
* superscript
* maybe bullets

If I implement TableCellEditor and extends another component that can handle the input above would this do the trick? Some leads?

// Mathias
[ December 05, 2005: Message edited by: Mathias Nilsson ]
You could create a TableCellRenderer that extends JTextPane but,
depending on exactly how you want it to behave, it could be a lot
of work.
Yes.... I have realized that...

Your editor and your renderer could use different components, so I
don't see what's so bad about a JLabel with text like:

<html>Sample <b>bold</b>, <i>italics</i> etc...</html>

As for your editor, how do you imagine entering superscripts and
supscripts? As a first approximation I would just edit the raw markup,
I mean if your users are untrained, anything else is at least as complex.
The users don't know HTML. I must see to that the input isn't wrong because I must parse the html tags and replace the tags against other tags. The result is a txt file with data marked up without <html><body> etc.

Do you think the JFrame will be heavy if every cell is a JTextPane?

NOTE: The JFrame is opened from a JApplet

// MAthias
>Do you think the JFrame will be heavy if every cell is a JTextPane?

it doesn't work that way. When you use a cell renderer, it can *reuse* a
single component to draw all its cells, like a rubber stamper.

Thanks.... but will i still be able to use the HTMLEditorKit in the JTextPane?

I have difficulties in getting the swing
This should solve all your problems...
The Element Interface @ The Swing Connection

This works with the DefaultStyledDocument implementaion of the Document Model used by the JTextComponent Component(Controller) in Swing.

Here's some scratchy code to help you along.
I'm sorry there aren't too may comments.

I went a little overboard with the renderer , but I know you'll forgive me!
The key mappings are:
  • Superscript: Alt + Up
  • Normal: Alt + Down
  • Bold: Ctrl + B

  • [ December 07, 2005: Message edited by: saager mhatre ]
    [ December 07, 2005: Message edited by: saager mhatre ]

    I saw this post a little late but i was in desparate need of it know.

    Thanks alot. Hope I can help you sometime....
    Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards

    All times above are in ranch (not your local) time.
    The current ranch time is
    Nov 18, 2017 14:35:51.