当前位置: 首页>>代码示例>>Java>>正文


Java JTextArea.requestFocus方法代码示例

本文整理汇总了Java中javax.swing.JTextArea.requestFocus方法的典型用法代码示例。如果您正苦于以下问题:Java JTextArea.requestFocus方法的具体用法?Java JTextArea.requestFocus怎么用?Java JTextArea.requestFocus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JTextArea的用法示例。


在下文中一共展示了JTextArea.requestFocus方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

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

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


注:本文中的javax.swing.JTextArea.requestFocus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。