当用户单击一个按钮时,我想显示一个应该至少有两个JTextField和两个JLabel的弹出窗体,因此JOptionPane.showInputDialog不可能使用.
问题1:通过使用defaulthighlighter,我可以使聚焦线变为蓝色.现在我想把它换成其他颜色.有谁知道如何更改此参数? - - 解决了
问题2:pos是我想要突出显示的子串的起始索引.我用setCaretPosition(pos); 更新显示内容.但它总是出现在窗口的底部.我希望它在顶部.谁能告诉我如何处理?
我使用一个演示来显示我的问题:
import java.awt.Color;
import java.net.MalformedURLException;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultHighlighter;
public class Test {
    public static void main(final String[] args) throws MalformedURLException {
        SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                init();
            } catch (BadLocationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
}
private static void init() throws BadLocationException {
    JFrame frame = new JFrame();
    final JTextArea textArea …