Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Multiple languages in one JLabel

Reply
Thread Tools

Multiple languages in one JLabel

 
 
Elly
Guest
Posts: n/a
 
      11-24-2004

I'm writing a utility that includes selecting and displaying files from the
desktop.

I'm running into problems since windows xp can have filenames made up of
characters from multiple languages.

How does one display such a string in a JLabel?

I thought of using a large font like MS Arial Unicode, but it isn't
distributable and the post I read mentioned that no large font exists to
handle all of the unicode character set in a complete manner for native
users of the various unicode characters.

Help?

-Elly

 
Reply With Quote
 
 
 
 
Michael Borgwardt
Guest
Posts: n/a
 
      11-24-2004
Elly wrote:

> I'm writing a utility that includes selecting and displaying files from the
> desktop.
>
> I'm running into problems since windows xp can have filenames made up of
> characters from multiple languages.
>
> How does one display such a string in a JLabel?


Just like any other string. Makes no difference to Java.

> I thought of using a large font like MS Arial Unicode, but it isn't
> distributable and the post I read mentioned that no large font exists to
> handle all of the unicode character set in a complete manner for native
> users of the various unicode characters.


I think you can assume that the default font will be able to display all
characters that a user in the default locale is likely to user. Windows
itself has the same problem, after all.
 
Reply With Quote
 
 
 
 
Elly
Guest
Posts: n/a
 
      11-24-2004
Michael Borgwardt <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> Elly wrote:
>
>> I'm writing a utility that includes selecting and displaying files
>> from the desktop.
>>
>> I'm running into problems since windows xp can have filenames made up
>> of characters from multiple languages.
>>
>> How does one display such a string in a JLabel?

>
> Just like any other string. Makes no difference to Java.


Java doesn't care about storing or using strings, but JLabel appears to
be incapable of displaying characters of different fonts within a single
label.

>
>> I thought of using a large font like MS Arial Unicode, but it isn't
>> distributable and the post I read mentioned that no large font exists
>> to handle all of the unicode character set in a complete manner for
>> native users of the various unicode characters.

>
> I think you can assume that the default font will be able to display
> all characters that a user in the default locale is likely to user.
> Windows itself has the same problem, after all.
>


In windows, a user can create filenames of mixed characters from
different languages.
These characters are all visible together in one filename on the windows
desktop.
If my Java app tries to display this file, it is unable to show all the
characters of different languages next to each other.
You have to choose one font or another for the JLabel, leaving square
boxes for the other characters.


-Elly



 
Reply With Quote
 
VisionSet
Guest
Posts: n/a
 
      11-24-2004

"Elly" <(E-Mail Removed)> wrote in message
news:Xns95AB71CE6934Ca@63.223.5.251...

>
> Java doesn't care about storing or using strings, but JLabel appears to
> be incapable of displaying characters of different fonts within a single
> label.
>



You change the font on the graphics object that is used to paint the
component.
A JLabel has no way of setting the font at predetermined points during its
paint routine.
However if you subclassed JLabel and overrode its paintComponent method then
you can do what you like!

--
Mike W


 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      11-24-2004
On Wed, 24 Nov 2004 19:11:59 GMT, Elly wrote:

> ..JLabel appears to
> be incapable of displaying characters of different fonts within a single
> label.


<sscce>
import java.awt.*;
import javax.swing.*;

/** Displays multiple fonts in a single JLabel using HTML formatting. */
public class MultiFontLabel {

public static void main(String args[]) {
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
Font allFonts[] = ge.getAllFonts();

StringBuffer sb = new StringBuffer();
sb.append( "<html><body><ul>" );
for (int ii=0; ii<allFonts.length; ii++) {
sb.append( "<li><font face='" + allFonts[ii].getFamily() +
"'>" + allFonts[ii].getFamily() + "</font>");
}
sb.append( "</ul></body></html>" );

JLabel l = new JLabel(sb.toString());
JScrollPane sp = new JScrollPane(l);
sp.setPreferredSize(new Dimension(300, 500));
JOptionPane.showMessageDialog(null, sp);
}
}
</sscce>
 
Reply With Quote
 
Elly
Guest
Posts: n/a
 
      11-24-2004
Andrew Thompson <(E-Mail Removed)> wrote in
news:bqgsktst7lmv$.njn2c1jkpnnz$(E-Mail Removed):

> On Wed, 24 Nov 2004 19:11:59 GMT, Elly wrote:
>
>> ..JLabel appears to
>> be incapable of displaying characters of different fonts within a
>> single label.

>
> <sscce>
> import java.awt.*;
> import javax.swing.*;
>
> /** Displays multiple fonts in a single JLabel using HTML formatting.
> */ public class MultiFontLabel {
>
> public static void main(String args[]) {
> GraphicsEnvironment ge =
> GraphicsEnvironment.getLocalGraphicsEnvironment();
> Font allFonts[] = ge.getAllFonts();
>
> StringBuffer sb = new StringBuffer();
> sb.append( "<html><body><ul>" );
> for (int ii=0; ii<allFonts.length; ii++) {
> sb.append( "<li><font face='" + allFonts[ii].getFamily() +
> "'>" + allFonts[ii].getFamily() + "</font>");
> }
> sb.append( "</ul></body></html>" );
>
> JLabel l = new JLabel(sb.toString());
> JScrollPane sp = new JScrollPane(l);
> sp.setPreferredSize(new Dimension(300, 500));
> JOptionPane.showMessageDialog(null, sp);
> }
> }
> </sscce>
>


Ahh, most excellent!

Much thanks Andrew T and Mike W

-Elly


 
Reply With Quote
 
VisionSet
Guest
Posts: n/a
 
      11-24-2004

"Andrew Thompson" <(E-Mail Removed)> wrote in message
news:bqgsktst7lmv$.njn2c1jkpnnz$(E-Mail Removed)...
> On Wed, 24 Nov 2004 19:11:59 GMT, Elly wrote:
>
> > ..JLabel appears to
> > be incapable of displaying characters of different fonts within a single
> > label.


> A JLabel has no way of setting the font at predetermined
> points during its paint routine.


Except if you use JTextComponents html abilities of course

--
Mike W


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
colors in JLabel vertigo Java 6 01-04-2004 09:27 PM
how to write in a Jlabel from a new class ? Damiano Michael Java 2 01-03-2004 08:19 AM
Using One XSLT and multiple XML Problem (One is XML and another one is XBRL) loveNUNO XML 2 11-20-2003 06:47 AM
Can JLabel have 2 rows of text? Rpng123 Java 6 10-10-2003 09:35 PM
JLabel behaves differently printing than in GUI Cindy Huyser Java 1 08-07-2003 09:53 PM



Advertisments