Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: JList display Hebrew right-to-left

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    8
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default JList display Hebrew right-to-left

    I have a JList and I want it to display Hebrew text starting on the right hand side. I've tried 2 different methods and each one displays the text from the left hand side, like English.
    First I tried a simple approach:

            ListCellRenderer cellRen1 = jList1.getCellRenderer();
            JLabel ren2 = (JLabel) cellRen1;
            ren2.setHorizontalTextPosition(JLabel.RIGHT);
            jList1.setCellRenderer(cellRen1);

    I could see the object number of cellRen1, which I cast to a JLabel. Then I set the direction to Hebrew. The forth line doesn't really do anything since I am putting back the same object. In any case, it didn't work.

    Next I tried making a ListCellRenderer. I checked in the debugger that it was being called for each string to be displayed. Only the first time did I see a change in the value of setHorizontalTextPosition. After I set it, it stayed set, but the text still displayed as English in direction.

           private void init1() {
            ListCellRenderer rend1 = new HebrewCellRenderer();
            jList1.setCellRenderer(rend1);
            }
     
            class HebrewCellRenderer implements ListCellRenderer {
            protected DefaultListCellRenderer defRen = new DefaultListCellRenderer();
     
            @Override
            public Component getListCellRendererComponent(JList jlist, Object o, int i, boolean bln, boolean bln1) {
            JLabel rend1 = (JLabel) defRen.getListCellRendererComponent(jlist, o, i, bln, bln1);
            rend1.setHorizontalTextPosition(JLabel.RIGHT);
            return rend1;
            }
            }

    The question is: why doesn't the text display right-to-left?

    Thanks,
    Ilan


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: JList display Hebrew right-to-left

    Hmmm.... I was in the same problem almost one and a half year ago, i was working on J2ME localization. I somehow managed to handle this. I can't remember at the moment. I have to see my code once again.....
    Well, i will get back to you.
    Meanwhile, you try to manage all this with the help of UNICODES for the local language.
    As far as i know, i did this work with the help of unicodes.
    And direction is not only with JLabel.RIGHT, there is something else that has to put in the code, to make it work from Right to Left.

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    8
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: JList display Hebrew right-to-left

    Thanks for the reply.
    I have no problem with the Hebrew itself, that displays just fine. Just it is in the wrong direction.
    I read the strings from a database (mySQL) and they come out correctly.
    If you can find out what is the added secret, that would be great.
    I can get combo boxes and text boxes to come out correctly, just JList is a problem.

  4. #4
    Junior Member
    Join Date
    Oct 2011
    Posts
    8
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: JList display Hebrew right-to-left

    In the hope that this might help somebody else, one doesn't need the setHorizontalTextPosition (and it doesn't help anyway). What one needs is
    jList1.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

Similar Threads

  1. Getting my paddle to move left and right in a straight line-STUCK
    By warnexus in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 20th, 2011, 08:06 PM
  2. Java:Evaluation of Mathematical Expression only from left to right only.
    By deepakl_2000 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: July 15th, 2011, 07:35 AM
  3. Left and Right rotation in a balanced binary tree problem
    By szuwi in forum Algorithms & Recursion
    Replies: 2
    Last Post: December 22nd, 2010, 07:20 PM
  4. Problem with jList
    By nextdigit in forum AWT / Java Swing
    Replies: 1
    Last Post: April 16th, 2010, 06:19 PM