2011-06-25 8 views
9

मेरे पास JTextArea के साथ है और मैं JTextArea के अभिविन्यास को दाएं से बाएं से सेट करने की कोशिश कर रहा हूं ताकि अंदर के पाठ दाएं से शुरू हो जाएंगे और स्क्रॉलबार बाईंJTextArea के दाएं से बाएं (जॉक्शनपेन के अंदर)

पर हो रहा की कोशिश की है, लेकिन वे निम्नलिखित उन्मुखीकरण की दिशा को प्रभावित नहीं किया जाएगा:

txt.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 
txt.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 
txt.setAlignmentX(JTextArea.RIGHT_ALIGNMENT); 

संपादित करें:

दो उत्तरों कैमिकर & ट्रैशगोड ने काम ठीक किया लेकिन मेरे कार्यक्रम में नहीं, जहां मैं अपने जेटीक्स्टएरिया को ऑब्जेक्ट संदेश के रूप में उपयोग करता हूं और इसे ऑप्शनपेन में पास करता हूं।

EDIT2:

मैं पता लगा कि setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); अगर मैं इसे JOptionPane सामग्री पर लागू होते हैं .. इस समस्या के लिए एक विकल्प समाधान है काम नहीं करता है?

मेरी कोड के समान:

import java.awt.*; 
import java.util.*; 
import javax.swing.*; 
public class TextArea extends JPanel 
{ 
    private JTextArea txt = new JTextArea(); 
    public TextArea() 
    { 
     setLayout(new GridLayout()); 
     txt.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 
     JScrollPane scroll = new JScrollPane(txt); 
     scroll.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 
     setPreferredSize(new Dimension(200,200)); 
     this.add(scroll); 
    } 
    private void display() 
    { 
     Object[] options = {this}; 
     JOptionPane pane = new JOptionPane(); 
     int option = pane.showOptionDialog(null, null, "Title", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); 
    } 
    public static void main(String[] args) 
    { 
     new TextArea().display(); 
    } 
} 
+0

पोस्ट अपने SSCCE है !!!! – camickr

+0

अंत में, एक एसएससीसीई, जिसे प्रत्येक प्रश्न के साथ पोस्ट किया जाना चाहिए। मेरा अपडेट देखें। – camickr

उत्तर

7

और स्क्रॉलबार छोड़ दिया

scrollPane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 

पर होगा तो यह अंदर का पाठ सही

से शुरू कर देंगे
textArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 

टेक्स्ट दाईं तरफ से शुरू होता है, लेकिन फिर भी लाइन की शुरुआत में डालने के बजाए टाइप करते समय अंत में जोड़ दिया जाता है।

अद्यतन:

मैं क्यों यह एक विकल्प फलक में काम नहीं करता है पता नहीं है। यहां एक साधारण समाधान है:

import java.awt.*; 
import java.awt.event.*; 
import java.util.*; 
import javax.swing.*; 
import javax.swing.event.*; 

public class Test 
{ 
    public static void main(String args[]) throws Exception 
    { 
     SwingUtilities.invokeLater(new Runnable() { 
      public void run() { 
       JTextArea textArea = new JTextArea(4, 20); 
       JScrollPane scrollPane = new JScrollPane(textArea); 
       JPanel panel = new JPanel(); 
       panel.add(scrollPane); 

       scrollPane.addAncestorListener(new AncestorListener() 
       { 
        public void ancestorAdded(AncestorEvent e) 
        { 
         JScrollPane scrollPane = (JScrollPane)e.getComponent(); 
         scrollPane.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 
        } 

        public void ancestorMoved(AncestorEvent e) {} 
        public void ancestorRemoved(AncestorEvent e) {} 
       }); 

       JOptionPane.showMessageDialog(null, panel); 
      } 
     }); 
    } 
} 
+0

अभी भी दाएं –

+0

पर मेरे लिए ठीक काम करता है, अपना एसएससीसीई पोस्ट करें! – camickr

+0

@camickr मैं कहां से अपना एसएससीसीई देख सकता हूं? –

7

ऐसा लगता है।

enter image description here

import java.awt.ComponentOrientation; 
import java.awt.EventQueue; 
import java.awt.GridLayout; 
import java.util.Locale; 
import javax.swing.JFrame; 
import javax.swing.JPanel; 
import javax.swing.JScrollPane; 
import javax.swing.JTextArea; 

/** @see http://stackoverflow.com/questions/6475320 */ 
public class RTLTextArea extends JPanel { 

    private static final String s = "مرحبا العالم"; 
    private JTextArea jta = new JTextArea(7, 5); 
    private Locale arabic = new Locale("ar", "KW"); 
    private ComponentOrientation arabicOrientation = 
     ComponentOrientation.getOrientation(arabic); 

    public RTLTextArea() { 
     this.setLayout(new GridLayout()); 
     this.add(new JScrollPane(jta)); 
     this.applyComponentOrientation(arabicOrientation); 
     for (int i = 0; i < 8; i++) { 
      jta.append(s + "\n"); 
     } 
    } 

    private void display() { 
     JFrame f = new JFrame("RTLTextAre"); 
     f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     f.add(this); 
     f.pack(); 
     f.setLocationRelativeTo(null); 
     f.setVisible(true); 
    } 

    public static void main(String[] args) { 
     EventQueue.invokeLater(new Runnable() { 

      @Override 
      public void run() { 
       new RTLTextArea().display(); 
      } 
     }); 
    } 
} 
+0

अरबी पाठ स्वागत में सुधार। – trashgod

+0

यह बहुत अच्छा काम करता है, लेकिन मुझे नहीं पता कि यह मेरे प्रोग्राम में क्यों काम नहीं करता है:/मुझे फिर से अपना कोड दोबारा जांचना होगा –

+0

और यही कारण है कि आपने अपना एसएससीसीई पोस्ट करने के लिए कहा था! हमें कोड लिखने की उम्मीद न करें, मैंने पहले ही आपको बताया है कि यह ठीक काम करता है। मुझे चम्मच खाने के कोड में विश्वास नहीं है जब आपको बस इतना करना है कि कोड की एक पंक्ति को आज़माएं। आप इस तरह से कुछ भी नहीं सीखते हैं। – camickr

2

इस लाइन

setComponentOrientation (ComponentOrientation.RIGHT_TO_LEFT)

परिवर्तन शब्दों के सही क्रम।

मैं इस परिणाम

KBytes 80,78

संबंधित मुद्दे