API有方法吗?
我的办法是取出String然后根据"\n"来截取。
下面是我的代码        // .....
        showButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                String shownText = textArea.getText();
                int lineCount = textArea.getLineCount();
                List<String> shownTxts = new ArrayList<String>();
                Pattern p = Pattern.compile("[^(\n)]+\n");
                Matcher m = p.matcher(shownText);
                while(m.find()) {
                    shownTxts.add(m.group());
                }
                System.out.println("lineCount:" + lineCount);
                if(!shownText.endsWith("\n")) {
                    try {
                        int lastLine = lineCount - 1;
                        int endLineStartPos = textArea.getLineStartOffset(lastLine);
                        int lastLineEndPos = textArea.getLineEndOffset(lastLine);
                        shownTxts.add(shownText.substring(endLineStartPos, lastLineEndPos));
                    } catch (Exception e) {
                        System.out.println(e.getMessage());
                    }
                }
                for(String txt : shownTxts) {
                    System.out.print(txt);
                }
            }
        });有更好的办法吗谢谢各位