Multiple languages in one JLabel

Discussion in 'Java' started by Elly, Nov 24, 2004.

  1. Elly

    Elly Guest

    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
    Elly, Nov 24, 2004
    #1
    1. Advertising

  2. 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.
    Michael Borgwardt, Nov 24, 2004
    #2
    1. Advertising

  3. Elly

    Elly Guest

    Michael Borgwardt <> wrote in
    news::

    > 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
    Elly, Nov 24, 2004
    #3
  4. Elly

    VisionSet Guest

    "Elly" <> 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
    VisionSet, Nov 24, 2004
    #4
  5. 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>
    Andrew Thompson, Nov 24, 2004
    #5
  6. Elly

    Elly Guest

    Andrew Thompson <> wrote in
    news:bqgsktst7lmv$.njn2c1jkpnnz$:

    > 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
    Elly, Nov 24, 2004
    #6
  7. Elly

    VisionSet Guest

    "Andrew Thompson" <> wrote in message
    news:bqgsktst7lmv$.njn2c1jkpnnz$...
    > 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
    VisionSet, Nov 24, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cindy Huyser
    Replies:
    1
    Views:
    508
    Cindy Huyser
    Aug 7, 2003
  2. Rpng123
    Replies:
    6
    Views:
    640
    Rpng123
    Oct 10, 2003
  3. Damiano Michael

    how to write in a Jlabel from a new class ?

    Damiano Michael, Jan 2, 2004, in forum: Java
    Replies:
    2
    Views:
    651
    Herman Timmermans
    Jan 3, 2004
  4. vertigo

    colors in JLabel

    vertigo, Jan 4, 2004, in forum: Java
    Replies:
    6
    Views:
    8,551
    Andrew Thompson
    Jan 4, 2004
  5. loveNUNO
    Replies:
    2
    Views:
    892
    loveNUNO
    Nov 20, 2003
Loading...

Share This Page