简体   繁体   English

如何更改 JTable 中的插入符号颜色

[英]How to change the caret color in a JTable

I'm creating a jTable were I can add new rows with text that can be modified, when I selected the row I want to rewrite the caret color is so light I can't see it so I don't know where I am writing.我正在创建一个 jTable 是否可以添加带有可修改文本的新行,当我选择要重写的行时,插入符号颜色太浅了,我看不到它,所以我不知道我在哪里写. How can I change the caret color?如何更改插入符号的颜色?

What you could do is get the editor component of your cell(s) and if it's a subclass of JTextComponent, call JTextComponent.setCaretColor .您可以做的是获取单元格的编辑器组件,如果它是 JTextComponent 的子类,请调用JTextComponent.setCaretColor By default, editors for a JTable are instances of JTextComponent.默认情况下,JTable 的编辑器是 JTextComponent 的实例。

Example:例子:

JTable yourTable = new JTable( ) {
    public Component prepareEditor( TableCellEditor editor, int row, int column ) {
        Component c = super.prepareEditor( editor, row, column );
        if( c instanceof JTextComponent )
            ((JTextComponent) c).setCaretColor( Color.RED );
        return c;
    }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM