第1个回答 推荐于2016-11-08
public class NewClass {
public static void main(String[] args) {
JFrame frame = new JFrame();
final JTextArea text = new JTextArea();
frame.setDefaultCloseOperation(3);
frame.setContentPane(text);
text.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent e) {
System.out.println(e.getMark());
try {
System.out.println(text.modelToView(text.getCaretPosition()));
} catch (BadLocationException ex) {
}
}
});
frame.setSize(500, 600);
frame.setVisible(true);
}
}本回答被提问者采纳