Example usage for javax.swing JTextArea viewToModel

List of usage examples for javax.swing JTextArea viewToModel

Introduction

In this page you can find the example usage for javax.swing JTextArea viewToModel.

Prototype

@Deprecated(since = "9")
public int viewToModel(Point pt) 

Source Link

Document

Converts the given place in the view coordinate system to the nearest representative location in the model.

Usage

From source file:Main.java

private static List<String> getLines(JTextArea textArea) {
    int lineHeight = getLineHeight(textArea);
    List<String> list = new ArrayList<String>();
    for (int num = 0;; num++) {
        int i = textArea.viewToModel(new Point(0, num * lineHeight));
        int j = textArea.viewToModel(new Point(0, (num + 1) * lineHeight));
        if (i == 0 && j == 0) {
            continue;
        }//from w ww .j ava2  s . c o m
        if (textArea.getDocument().getLength() == i && i == j) {
            break;
        }
        String s = removeTrailingNewLine(textArea.getText().substring(i, j));
        list.add(s);
    }
    return list;
}