當前位置: 首頁>>代碼示例>>Java>>正文


Java JTextArea.getLineEndOffset方法代碼示例

本文整理匯總了Java中javax.swing.JTextArea.getLineEndOffset方法的典型用法代碼示例。如果您正苦於以下問題:Java JTextArea.getLineEndOffset方法的具體用法?Java JTextArea.getLineEndOffset怎麽用?Java JTextArea.getLineEndOffset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.JTextArea的用法示例。


在下文中一共展示了JTextArea.getLineEndOffset方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: actionPerformed

import javax.swing.JTextArea; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(ActionEvent e) {
    JTextArea currentEditor = observer.getActiveEditor().getEditor();
    Document document = currentEditor.getDocument();
    Caret caret = currentEditor.getCaret();

    int startCaret = Math.min(caret.getDot(), caret.getMark());
    int endCaret = Math.max(caret.getDot(), caret.getMark());

    try {

        int startLine = currentEditor.getLineOfOffset(startCaret);
        int endLine = currentEditor.getLineOfOffset(endCaret);
        int fromPos = currentEditor.getLineStartOffset(startLine);
        int length = currentEditor.getLineEndOffset(endLine) - fromPos;

        String text = currentEditor.getText(fromPos, length);
        text = sortLinesDesc(text);
        document.remove(fromPos, length);
        document.insertString(fromPos, text, null);
        caret.setDot(fromPos);
        caret.moveDot(fromPos + length);
        currentEditor.requestFocus();
    } catch (BadLocationException e1) {
        observer.errorMessage(e1);
    }

}
 
開發者ID:fgulan,項目名稱:java-course,代碼行數:32,代碼來源:SortLinesDescendingAction.java

示例2: actionPerformed

import javax.swing.JTextArea; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(ActionEvent e) {
    JTextArea currentEditor = observer.getActiveEditor().getEditor();
    Document document = currentEditor.getDocument();
    Caret caret = currentEditor.getCaret();

    int startCaret = Math.min(caret.getDot(), caret.getMark());
    int endCaret = Math.max(caret.getDot(), caret.getMark());

    try {

        int startLine = currentEditor.getLineOfOffset(startCaret);
        int endLine = currentEditor.getLineOfOffset(endCaret);
        int fromPos = currentEditor.getLineStartOffset(startLine);
        int length = currentEditor.getLineEndOffset(endLine) - fromPos;

        String text = currentEditor.getText(fromPos, length);
        text = sortLinesAsc(text);
        document.remove(fromPos, length);
        document.insertString(fromPos, text, null);
        caret.setDot(fromPos);
        caret.moveDot(fromPos + length);
        currentEditor.requestFocus();
    } catch (BadLocationException e1) {
        observer.errorMessage(e1);
    }

}
 
開發者ID:fgulan,項目名稱:java-course,代碼行數:32,代碼來源:SortLinesAscendingAction.java

示例3: actionPerformed

import javax.swing.JTextArea; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(ActionEvent e) {
    JTextArea currentEditor = observer.getActiveEditor().getEditor();
    Document document = currentEditor.getDocument();
    Caret caret = currentEditor.getCaret();

    int startCaret = Math.min(caret.getDot(), caret.getMark());
    int endCaret = Math.max(caret.getDot(), caret.getMark());

    try {

        int startLine = currentEditor.getLineOfOffset(startCaret);
        int endLine = currentEditor.getLineOfOffset(endCaret);
        int fromPos = currentEditor.getLineStartOffset(startLine);
        int length = currentEditor.getLineEndOffset(endLine) - fromPos + 1;

        String text = currentEditor.getText(fromPos, length);
        text = removeLines(text);
        document.remove(fromPos, length - 1);
        document.insertString(fromPos, text, null);
        caret.setDot(fromPos);
        caret.moveDot(length - 1);
        currentEditor.requestFocus();
    } catch (BadLocationException e1) {
        observer.errorMessage(e1);
    }
}
 
開發者ID:fgulan,項目名稱:java-course,代碼行數:31,代碼來源:UniqueLinesAction.java

示例4: trunkTextArea

import javax.swing.JTextArea; //導入方法依賴的package包/類
public void trunkTextArea(JTextArea txtWin){
    int numLinesToTrunk = txtWin.getLineCount() - SCROLL_BUFFER_SIZE;
    if(numLinesToTrunk > 0)
    {
        try
        {
            int posOfLastLineToTrunk = txtWin.getLineEndOffset(numLinesToTrunk - 1);
            txtWin.replaceRange("",0,posOfLastLineToTrunk);
        }
        catch (BadLocationException ex) {
            ex.printStackTrace();
        }
    }
}
 
開發者ID:jonasxiao,項目名稱:FinalSpeed,代碼行數:15,代碼來源:LogFrame.java


注:本文中的javax.swing.JTextArea.getLineEndOffset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。