Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6059415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:42:27+00:00 2026-05-23T08:42:27+00:00

I have JScrollPane with JTextArea inside it and I am trying to set the

  • 0

I have JScrollPane with JTextArea inside it and I am trying to set the JTextArea’s orientation from right to left so the text inside it will start from the right and the scrollbar will be on the left

I’ve tried the following but they didn’t affect the direction of the orientation:

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

EDIT:

the two answers camickr & trashgod provided work fine but not in my program where I use my JTextArea as an object Message and pass it to OptionPane.

EDIT2:

I figured out that setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); doesn’t work if I apply it on the JOptionPane contents .. is there an alternative solution to this issue?

Similar to my code:

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();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:42:28+00:00Added an answer on May 23, 2026 at 8:42 am

    and the scrollbar will be on the left

    scrollPane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    

    so the text inside it will start from the right

    textArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    

    The text starts on the right side, but still gets append to the end as you type instead of being inserted at the beginning of the line.

    Update:

    I don’t know why it doesn’t work in an option pane. Here is a simple solution:

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add text to a JTextArea, and to have an auto scrollbar
I currently have a setup where I have a JTextArea inside a JScrollPane so
I have a JScrollPane with a JTextArea set as its view port. I update
I have embedded a JTextArea on a JScrollPane and am using that JTextArea for
I have a JTable inside of a JScrollPane . I am creating a custom
I want to have a JEditorPane inside a JScrollPane. When the user clicks a
I have a JTextArea and it's riding on top of a JScrollPane. Anyways, I
I have a JTextArea in (multiple) JScrollPane in a JTabbedPane. I need to access
I have a JScrollPane and JPanel inside it(I want to draw on JPanel). Also
I have been trying to use JScrollPane with my applet, but it doesn't work.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.