Swing JTextPane中如何获得某行的文本?

来源:百度知道 编辑:UC知道 时间:2024/05/14 12:52:23
最好是取得鼠标所在行的文本~~~~
解决了给高分!!

不好意思,没有实现取鼠标所在行文本
但可以取到鼠标选择部分的文本
就是你用鼠标在JTextPane的文本中拖拽后选择的文本部分
请自行在JTextPane中输入一些内容测试

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextPane;

public class JTextPaneDemo extends JFrame {
private static final String LABEL_INIT="Press the GET button...";
private static final String LABEL_WARNING="Press choose the text in Pane...";

JTextPane textPane = null;
JButton button = null;
JLabel label = null;

public JTextPaneDemo(){
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new BorderLayout());
initFrame();
}

private void initFrame(){
textPane = new JTextPane();
textPane.setText("Please Input...");<