Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
How to diplay x sup y on JLabel?
Qunfeng Wang
Ranch Hand
Posts: 434
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I create my own SupLabel extends JLabel and override its paintComponent method. I use the HTML to draw what I want. But it just draws the plain html
string
! Below is my code. Anyone sheds some light on me? Thanks.
import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.*; public class SupLabel extends JLabel{ private int x; private int y; private String s; public SupLabel(int x, int y) { this.x = x; this.y = y; s = "<html>" + x + "<sup>" + y + "</sup></html>"; } protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.drawString(s, 10, 10); } }
To be or not to be. It's a question.
Edwin Dalorzo
Ranch Hand
Posts: 961
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
But JLabel is already capable of painting HTML text, you do not need to redefine the paint method.
It is as simple as
public SupLabel(int x, int y) { this.x = x; this.y = y; s = "<html>" + x + "<sup>" + y + "</sup></html>"; setText(s); }
Is it not?
[ October 23, 2006: Message edited by: Edwin Dalorzo ]
Qunfeng Wang
Ranch Hand
Posts: 434
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks man
To be or not to be. It's a question.
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to use JSlider to adjust Text in a JPanel
Messagebox with Mouseevent
looking for a graphical representation
Enter # in JTextField, draw = # ovals, use JBottons to color ovals???
Help! Having trouble animating translucent window.
More...