完全痴線 – JTextComponent個setCaretPosition完來係錯

完全痴線 – JTextComponent個setCaretPosition完來係錯

2019/07/13 Netbeans Programming 0

如果你放”abc\ndef”落JTextComponent, 佢會變Q左”abc\r\ndef”, 連帶影響埋setCaretPosition()會錯位,補救方法如下:

int count = StringUtils.countMatches(jTextComponent.getText().substring(0, data.caretPosition), "\r\n");
jTextComponent.setCaretPosition(data.caretPosition - count);

經過修正之後, 我個netbeans outline plugin回復正常了

Leave a Reply

Your email address will not be published.