aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Super, subscript with JLabel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Super, subscript with JLabel" Watch "Super, subscript with JLabel" New topic
Author

Super, subscript with JLabel

Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
Hi!

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 ]

SCJP1.4
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
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.


bitguru blog
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
Yes.... I have realized that...

Thanks!
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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.


There is no emoticon for what I am feeling!
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
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
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
>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.
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
Ok!

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

I have difficulties in getting the swing
saager mhatre
Ranch Hand

Joined: Dec 20, 2000
Posts: 61
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 ]
    Mathias Nilsson
    Ranch Hand

    Joined: Aug 21, 2004
    Posts: 367
    Hi!

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

    Thanks alot. Hope I can help you sometime....
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Super, subscript with JLabel
     
    Similar Threads
    Using Mutilple Cell Editor on single column of JTable
    JTable
    JTable CellRenderer with HTML in JLabel
    JTable cells and html
    Super and sub string in java to string