[英]How to read last word or last line in DocumenListener
我为JEditorPane实现DocumentListener(需要有关方法insertUpdate(DocumentEvent e)的帮助)。 如何阅读最后一个单词或最后一行(行之间用'\\ n'分隔,单词之间用''分隔)?
实用程序类可与格式化内容一起使用,例如html
public static final int getWordStart(JTextComponent c, int offs) throws BadLocationException
public static final int getWordEnd(JTextComponent c, int offs) throws BadLocationException
要获得JEditorPane中的最后一行,请在编辑器中的\\n
上拆分文本,如下所示:
String text = editor.getText();
String[] lines = text.split("\n");
String lastLine = lines[lines.length-1];
System.out.println("Last line: " + lastLine);
同样,要获取最后一个单词,请在空间上拆分最后一行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.