This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes how to build swing applications with bidirectional support Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to build swing applications with bidirectional support" Watch "how to build swing applications with bidirectional support" New topic
Author

how to build swing applications with bidirectional support

Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
how to build swing applications with bidirectional support?

I have build the swing application with english language support, Now they want the same application in arabic language...

i need some suggestions in implementing the application compatible to arabic language...


Abhishek
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
There are internationalisation topics in the Java Tutorials, here and here.
Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
thanks for the reply, i have already gone through these links...

the swing application has to be implemented in arabic culture...the major problem is aligning the swing components from right to left...

currently i have build the application, where components are aligned in left to right fashion.

My problem is how to shift the components from left to right and right to left based on the user selected Locale.

Is it possible possible to modify the appln. in such a way that it will support both english and arabic languages or else i have to rebuild the same application in arabic culture...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
I tried looking in the API index for LEFT_TO_RIGHT and found it in ComponentOrientation. If you click on the USE tab at the top, you find it is used in classes like Component. I think one of those methods will allow you to specify an orientation.
You can probably set the orientation depending on the Locale for the computer being used; there is a getOrientation method which seems to provide that functionality.
Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
I have tried in this way...but the Jpanel components are not aligned in arabic culture i.e. from right to left

I have build the JFrame using netbeans 5.0

/*
* I18NFrame.java
*
* Created on October 21, 2008, 11:12 PM
*/

package i18n;

import java.awt.ComponentOrientation;
import java.util.Locale;

/**
*
* @author Administrator
*/
public class I18NFrame extends javax.swing.JFrame {

/** Creates new form I18NFrame */
public I18NFrame() {
initComponents();


this.getContentPane().applyComponentOrientation(ComponentOrientation.getOrientation(new Locale("ar","SA")));


jPanel1.setComponentOrientation(ComponentOrientation.getOrientation(new Locale("ar")));

jPanel1.applyComponentOrientation(ComponentOrientation.getOrientation(new Locale("ar","SA")));

}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Name");

jTextField1.setText("abhishek");

jLabel2.setText("Address");

jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);

org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(39, 39, 39)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel2))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 105, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap(102, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(31, 31, 31)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel1)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(22, 22, 22)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel2)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap(114, Short.MAX_VALUE))
);

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new I18NFrame().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;
// End of variables declaration

}


tanks in advance
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Please Use Code Tags.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Please show us where in your code you used LEFT_TO_RIGHT or RIGHT_TO_LEFT.
Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
thanks for the reply...
here is the part of the code.....
this.getContentPane().applyComponentOrientation(ComponentOrientation.getOrientation(new Locale("ar","SA")));


jPanel1.setComponentOrientation(ComponentOrientation.getOrientation(new Locale("ar")));

jPanel1.applyComponentOrientation(ComponentOrientation.getOrientation(new Locale("ar","SA")));

the orientation of text inside the components is working, but the components
are not aligned from right to left in arabic locale
Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
just have a look at this image files..

English Locale..(image1)
http://www.flickr.com/photos/26246340@N00/119723963/

Arabic Locale..(image2)
http://www.flickr.com/photos/26246340@N00/119723964/

I want exactly the same functionality...

Is it possible to implement both locales functionality in a single JFrame.
i.e. if the user selects English Locale, the JFrames gui should appear in english culture.(as shown in image1)

if the user selects Arabic Locale, the same JFrames gui should appear in arabic culture. (as shown in image2)

If it is possible, please help me..

thanks again
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Have you checked that the Locale is interpreting "ar" as Arabic? And where's "SA?" Is is South Africa?
Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
thanks for the reply...

http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html.
"SA" is the two letter country code for Saudi Arabia
I have also checked removing the country code from the Locale, but is of no use..
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Just another cross poster.
http://forums.sun.com/thread.jspa?threadID=5341216


luck, db
There are no new questions, but there may be new answers.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to build swing applications with bidirectional support
 
Similar Threads
mySQL is it support arabic language and how?
Localization
Arabic letters in Text object
Arabic letters in Text object
Arabic numbers input problem(Very Urgent)