JTextArea là một lớp con của JTextComponent và là thành phần văn bản nhiều dòng để hiển thị văn bản hoặc cho phép người dùng nhập văn bản. JTextArea tạo ra giao diện CaretListener khi triển khai chức năng JTextArea. Mặc định, JTextArea cho phép hướng từ trái sang phải, nếu người dùng muốn nhập văn bản từ phải sang trái dùng phương thức setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT) của JTextArea.
Ví dụ
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();
}
}
Kết quả
