Results 1 to 4 of 4
  1. #1
    random4534 is offline Member
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Question JLabel Rendering

    I'm constructing a JLabel with a String that contains foreign characters. The JLabel is rendering the characters in reverse order. Is there a way to disable this behavior? I would like the displayed character order to match the one in the inputed String.

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    you could take the String and reverse it then send the reversed string to JLabel which will in turn reverse that string(which will show up in the correct order).

    Like orginalString = "abcd" then do a loop from originalString.length to 0 using charAt() to create a new string. JLabel.setText(newString)

  3. #3
    random4534 is offline Member
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Default

    I discovered that it is not actually reversing the characters. If you use the below array to create a String and then create a JLabel using this String, the JLabel displays the ".txt" portion of the String first. I would expect the ".txt" part to be displayed at the end, since the last four elements represent it.

    int[] unicode = {0x0628, 0x0628, 0x0628, 0x0628, 0x0628, 0x002E, 0x0074, 0x0078, 0x0074};

    However, when I look at this String in the debugger, I see the foreign characters first followed by the ".txt" part. Also, when I convert the String into a sequence of UTF-8 bytes, create a file using them, and open the file with notepad, I see exactly what the debugger is showing me.

    I'm not sure how the JLabel renders characters in a String. Any ideas for this behavior?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    You're mixing right-to-left and left-to-right scripts in the same string. The direction is determined from the first character.

    You can confirm this by adding 0x0041 ("A") as the first element of the array.

    And your remark:
    > I would expect the ".txt" part to be displayed at the end
    It is being displayed at the end. For right-to-left scripts, the end is at the left.

    db

Similar Threads

  1. jLabel
    By Matty in forum AWT / Swing
    Replies: 3
    Last Post: 09-22-2008, 10:22 PM
  2. JLabel Array?
    By serfster in forum New To Java
    Replies: 1
    Last Post: 06-11-2008, 03:13 AM
  3. GUI - JLabel
    By Azndaddy in forum New To Java
    Replies: 8
    Last Post: 05-02-2008, 07:03 AM
  4. JLabel
    By Jack in forum AWT / Swing
    Replies: 2
    Last Post: 07-02-2007, 01:55 PM
  5. JLabel
    By Freddie in forum AWT / Swing
    Replies: 2
    Last Post: 05-29-2007, 02:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •