- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we set the orientation of a JTextArea from right to left in Java?
A JTextArea is a subclass of JTextComponent class and it is a multi-line text component to display the text or allow a user to enter the text. A JTextArea can generate a CaretListener interface when we are trying to implement the functionality of the JTextArea. By default, a JTextarea allows the orientation from left to right, if the user wants to enter a text from right to left by using the setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT) method of JTextArea class.
Example
import java.awt.*; import javax.swing.event.*; import javax.swing.*; public class JTextAreaOrientationTest extends JFrame { private JTextArea textArea; public JTextAreaOrientationTest() { setTitle("JTextAreaOrientation Test"); textArea = new JTextArea(); textArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); add(new JScrollPane(textArea), BorderLayout.CENTER); setSize(400, 275); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); } public static void main(String args[]) { new JTextAreaOrientationTest(); } }
Output
- Related Articles
- How can we hide left/right pane of a JSplitPane programmatically in Java?
- How can we display the line numbers inside a JTextArea in Java?
- How can we disable cut, copy and paste functionality of a JTextArea in Java?
- How can I append text to JTextArea in Java?
- How can we implement line wrap and word wrap text inside a JTextArea in Java?
- Can we select only some of the text in JTextArea?
- How can we set the margin to a JButton in Java?
- How can we set a border to JCheckBox in Java?
- Java Program to set JTextArea to wrap by word in Java
- How can we set the background color to a JPanel in Java?
- How can we set the shortcut key to a JButton in Java?
- How to create a Box to display components from left to right in Java
- Set the flex items horizontally from right to left with CSS
- How can we convert list to Set in Java?
- How can we set a background color to JSplitPane in Java?

Advertisements