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


Java JTextArea.getDocument方法代碼示例

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


在下文中一共展示了JTextArea.getDocument方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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 position = currentEditor.getCaret();

    int len = Math.abs(currentEditor.getCaret().getDot()
            - currentEditor.getCaret().getMark());
    int offset = Math.min(currentEditor.getCaret().getDot(), currentEditor
            .getCaret().getMark());

    try {
        String text = document.getText(offset, len);
        text = lowerCase(text);
        document.remove(offset, len);
        document.insertString(offset, text, null);
        // Reselect text
        position.setDot(offset);
        position.moveDot(offset + len);
        currentEditor.requestFocus();
    } catch (BadLocationException e1) {
        observer.errorMessage(e1);
    }
}
 
開發者ID:fgulan,項目名稱:java-course,代碼行數:28,代碼來源:LowerCaseAction.java

示例2: actionPerformed

import javax.swing.JTextArea; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(ActionEvent arg0) {
    JTextArea currentEditor = observer.getActiveEditor().getEditor();
    Document doc = currentEditor.getDocument();
    int len = Math.abs(currentEditor.getCaret().getDot()
            - currentEditor.getCaret().getMark());
    int offset = Math.min(currentEditor.getCaret().getDot(), currentEditor
            .getCaret().getMark());

    try {
        String text = doc.getText(offset, len);
        text = toggleCase(text);
        doc.remove(offset, len);
        doc.insertString(offset, text, null);
        currentEditor.getCaret().setDot(offset);
        currentEditor.getCaret().moveDot(offset + len);
        currentEditor.requestFocus();
    } catch (BadLocationException e1) {

    }
}
 
開發者ID:fgulan,項目名稱:java-course,代碼行數:25,代碼來源:InvertCaseAction.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 position = currentEditor.getCaret();

    int len = Math.abs(currentEditor.getCaret().getDot()
            - currentEditor.getCaret().getMark());
    int offset = Math.min(currentEditor.getCaret().getDot(), currentEditor
            .getCaret().getMark());

    try {
        String text = document.getText(offset, len);
        text = upperCase(text);
        document.remove(offset, len);
        document.insertString(offset, text, null);
        position.setDot(offset);
        position.moveDot(offset + len);
        currentEditor.requestFocus();
    } catch (BadLocationException e1) {
        observer.errorMessage(e1);
    }
}
 
開發者ID:fgulan,項目名稱:java-course,代碼行數:27,代碼來源:UpperCaseAction.java

示例4: getDocument

import javax.swing.JTextArea; //導入方法依賴的package包/類
private Document getDocument(String str) {
    JTextArea ta = new JTextArea(str);
    if (str != null && str.length() > 0) {
        ta.setCaretPosition(1);
    }
    Document doc = ta.getDocument();
    return doc;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:DocumentFinderTest.java

示例5: func_164247_a

import javax.swing.JTextArea; //導入方法依賴的package包/類
public void func_164247_a(final JTextArea p_164247_1_, final JScrollPane p_164247_2_, final String p_164247_3_)
{
    if (!SwingUtilities.isEventDispatchThread())
    {
        SwingUtilities.invokeLater(new Runnable()
        {
            public void run()
            {
                MinecraftServerGui.this.func_164247_a(p_164247_1_, p_164247_2_, p_164247_3_);
            }
        });
    }
    else
    {
        Document document = p_164247_1_.getDocument();
        JScrollBar jscrollbar = p_164247_2_.getVerticalScrollBar();
        boolean flag = false;

        if (p_164247_2_.getViewport().getView() == p_164247_1_)
        {
            flag = (double)jscrollbar.getValue() + jscrollbar.getSize().getHeight() + (double)(serverGuiFont.getSize() * 4) > (double)jscrollbar.getMaximum();
        }

        try
        {
            document.insertString(document.getLength(), p_164247_3_, (AttributeSet)null);
        }
        catch (BadLocationException var8)
        {
            ;
        }

        if (flag)
        {
            jscrollbar.setValue(Integer.MAX_VALUE);
        }
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:39,代碼來源:MinecraftServerGui.java

示例6: 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

示例7: 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

示例8: 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

示例9: appendLine

import javax.swing.JTextArea; //導入方法依賴的package包/類
public void appendLine(final JTextArea textArea, final JScrollPane scrollPane, final String line)
{
    try
    {
        latch.await();
    } catch (InterruptedException e){} //Prevent logging until after constructor has ended.
    if (!SwingUtilities.isEventDispatchThread())
    {
        SwingUtilities.invokeLater(new Runnable()
        {
            public void run()
            {
                MinecraftServerGui.this.appendLine(textArea, scrollPane, line);
            }
        });
    }
    else
    {
        Document document = textArea.getDocument();
        JScrollBar jscrollbar = scrollPane.getVerticalScrollBar();
        boolean flag = false;

        if (scrollPane.getViewport().getView() == textArea)
        {
            flag = (double)jscrollbar.getValue() + jscrollbar.getSize().getHeight() + (double)(SERVER_GUI_FONT.getSize() * 4) > (double)jscrollbar.getMaximum();
        }

        try
        {
            document.insertString(document.getLength(), line, (AttributeSet)null);
        }
        catch (BadLocationException var8)
        {
            ;
        }

        if (flag)
        {
            jscrollbar.setValue(Integer.MAX_VALUE);
        }
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:43,代碼來源:MinecraftServerGui.java


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