- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
Advertisements