I've looked through a ton of stuff on the web, and haven't come up with
a decent answer to this question:
How can I display the TM symbol in Java?
I'm running JDK 1.2.2, and I'm trying to display that symbol in a
JTextPane. I've tried every font in Java, as well as those it can read from
my Windows system, and none of them like it. They'll show the Registered
(R) or Copywrite (c) symbols without a problem, but the Trademark TM is a
consistent problem.
Same goes for the entire Symbol True Type Font for that matter.
There must be a way around this - I need to be able to read it from a
file, show it on screen, then write it back.
Please help!
Thanks........
Bryan
I tried the following code on Windoze and it displayed a TM very nicely:
JFrame f = new JFrame();
f.getContentPane().setLayout( new BorderLayout() );
f.getContentPane().add( new JLabel( "Java\u2122" ),
BorderLayout.CENTER );
f.pack();
f.show();
--
Dale King
"Bryan O'Malley" <br...@chameleon-systems.com> wrote in message
news:96epri$ogs$1...@paxfeed.eni.net...
> Are you properly specifying the symbol? Note that the trademark symbol in
> Unicode is \u2122 not character 153. Which platform are you running on?
> Windoze should have no problem whatsoever. Not sure about Linux though.
>
> I tried the following code on Windoze and it displayed a TM very nicely:
>
> JFrame f = new JFrame();
> f.getContentPane().setLayout( new BorderLayout() );
> f.getContentPane().add( new JLabel( "Java\u2122" ),
> BorderLayout.CENTER );
> f.pack();
> f.show();
The above code works on Linux also.
Brian Simpson
> I'm running JDK 1.2.2, and I'm trying to display that symbol in a
>JTextPane. I've tried every font in Java, as well as those it can read from
>my Windows system, and none of them like it. They'll show the Registered
>(R) or Copywrite (c) symbols without a problem, but the Trademark TM is a
>consistent problem.
There are two problems. The easy one is getting the unicode char
\uxxxx number. See Unicode in the Java glossary. However, most
people won't have a font installed that can display it. What do do?
Fudge as you would in HTML with the equivalent of this Good
Thing<sup>TM</sup>
--
Please consult the JAVA GLOSSARY for almost any
Java-related question.
If the answer is not there, COMPLAIN!
See http://mindprod.com/jgloss.html
or http://209.153.246.39/jgloss.html
Answers to the six most Frequently Asked Questions:
1) for conversion problems, see "conversion". .
2) for I/O problems, see the "File I/O Amanuensis" and "File".
3) if you want to create a *.exe, see "native compiler".
4) if you are new to Java, see "getting started".
5) to spawn an external program see "exec".
6) See "error messages" in the Java glossary.
--
Roedy Green, Canadian Mind Products
Custom computer programming since 1963
>Fudge as you would in HTML with the equivalent of this Good
>Thing<sup>TM</sup>
There is a predefined entity:
™
Regards,
Marco
--
Java programming tips: http://jiu.sourceforge.net/javatips.html
>
> >Fudge as you would in HTML with the equivalent of this Good
> >Thing<sup>TM</sup>
>
> There is a predefined entity:
>
> ™
True, but if your fonts don't have this symbol or you have an old browser
which doesn't recognise ™ then nothing (useful) would be displayed.
Which is why Roedy suggested the fudging alternative.
Mark Thornton
>True, but if your fonts don't have this symbol or you have an old browser
>which doesn't recognise ™ then nothing (useful) would be displayed.
>Which is why Roedy suggested the fudging alternative.
Hmm, I didn't know that. I thought those things were defined once and
never touched again.
"Marco Schmidt" <marcos...@geocities.com> wrote in message
news:SIyLOh9rxqaorBDXHyjP=gl9...@4ax.com...
Where? Certainly putting ™ into your Java source code doesn't turn
it into a Unicode TM symbol. \u2122 does that instead.
--
Jon Skeet - sk...@pobox.com
http://www.pobox.com/~skeet
http://developer.java.sun.com/developer/bugParade/bugs/4355528.html
Attached message:
-------------------
The Plot thickens:
Try this with your example below.
JFrame f = new JFrame();
JLabel jl = new JLabel("Java\u2122" );
f.getContentPane().setLayout( new BorderLayout() );
f.getContentPane().add( jl, BorderLayout.CENTER );
jl.setFont(new Font("Dialog", Font.BOLD, 32));
f.pack();
f.show();
Everything works fine. BOLD is the default for a JLabel, so my setFont
is fairly redundant, except that I made it larger (for my aging eyes!).
Now try this:
JFrame f = new JFrame();
JLabel jl = new JLabel("Java\u2122" );
f.getContentPane().setLayout( new BorderLayout() );
f.getContentPane().add( jl, BorderLayout.CENTER );
jl.setFont(new Font("Dialog", Font.PLAIN, 32));
f.pack();
f.show();
Wham! We've got a problem. For some reason, the plain font doesn't
include the TM character, but the bold version does. This must be a bug,
right?
--
Dale King
I created a new function to call instead of setText() on the JTextPane, I
call this function, and pass it the JTextPane itself, the String to be
inserted, the position to insert it, and they style to use for the TM. I
then strip out the ASCII TM character, and replace it with the Unicode.
Hopefully this will help someone else out in the future......
Bryan
final static int TMASCII = 8482; // Character code for 'T' in ASCII
final static String TMUnicode = "\u2122"; // Character code for 'T' in
Unicode
private Style TMStyle = sc.addStyle("TMStyle", null);
// This appears in the constructor of my class
StyleConstants.setFontFamily(TMStyle, "Arial");
static void DoTheInsert(JTextPane tp, String s, int caretpos, Style st)
throws BadLocationException
{
int idx = 0;
int oldpos = 0;
String temp = s;
idx = s.indexOf(TMASCII);
while (idx > 0)
{
temp = s.substring(oldpos, idx);
tp.getStyledDocument().insertString(caretpos, temp, null);
tp.getStyledDocument().insertString(caretpos + (idx - oldpos),
TMUnicode, st);
oldpos = idx + 1;
idx = s.indexOf(TMASCII, oldpos);
}
tp.getStyledDocument().insertString(caretpos + oldpos,
s.substring(oldpos), null);
}