jTextarea在开始键入之前,不会在右侧设置文本指示器

问题描述 投票:0回答:1
我在这里遇到的唯一问题是,文本指示灯始终显示在左侧,直到我开始键入。

在键入之前:

enter image description here 打字后:

enter image description here JTextArea textArea = new JTextArea(); textArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); JScrollPane scroll = new JScrollPane(textArea); scroll.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

there是完整的代码:
import java.awt.ComponentOrientation;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class Test extends JFrame {
    
    public Test() {
        this.setSize(300, 100);
        
        JTextArea textArea = new JTextArea();
        textArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        JScrollPane scroll = new JScrollPane(textArea);
        scroll.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        
        scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        this.add(scroll);
        this.setVisible(true);
    }

}

我在Windows 10上使用Java 11fy.
    

这似乎对我有用(在Mac上进行了测试)。
java swing jtextarea
1个回答
2
投票

有点骇客,但正如您所说的。没有写任何东西,caret是默认为左侧的。


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.