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


Java JTextComponent.hasFocus方法代码示例

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


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

示例1: modifiedUpdate

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void modifiedUpdate(DocumentEvent evt, int offset, int endOffset, int setDotOffset) {
    // For typing modification ensure that the last caret will be visible after the typing modification.
    // Otherwise the caret would go off the screen when typing at the end of a long line.
    // It might make sense to make an implicit dot setting to end of the modification
    // but that would break existing tests like TypingCompletionUnitTest wihch expects
    // that even typing modifications do not influence the caret position (not only the non-typing ones).
    boolean typingModification = DocumentUtilities.isTypingModification(evt.getDocument());
    JTextComponent c = component;
    scrollToLastCaret |= typingModification && (c != null && c.hasFocus());

    if (!implicitSetDot(evt, setDotOffset)) {
        // Ensure that a valid atomicSectionImplicitSetDotOffset value
        // will be updated by the just performed document modification
        if (atomicSectionImplicitSetDotOffset != Integer.MAX_VALUE) {
            atomicSectionImplicitSetDotOffset = DocumentUtilities.fixOffset(
                    atomicSectionImplicitSetDotOffset, evt);
        }
    }

    if (inAtomicSection) {
        extendAtomicSectionChangeArea(offset, endOffset);
    } else { // Not in atomic section
        invalidateCaretBounds(offset, endOffset);
        updateAndFireChange();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:EditorCaret.java

示例2: paste

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * Copies the text contents of the system clipboard to the text component.
 *
 * @param textComponent
 */
public static void paste(JTextComponent textComponent) {
    String contents = ClipboardHandlerFactory.getClipboardHandler()
            .getContents();
    if (contents != null) {
        StringBuffer buffer = new StringBuffer();
        char c;
        for (int i = 0, n = contents.length(); i < n; i++) {
            c = contents.charAt(i);
            // Not to copy a null character
            if (c != 0) {
                buffer.append(c);
            }
        }
        textComponent.replaceSelection(buffer.toString());
    }
    if (!textComponent.hasFocus()) {
        textComponent.requestFocus();
    }
}
 
开发者ID:YcheCourseProject,项目名称:DIA-Umpire-Maven,代码行数:25,代码来源:TextComponentUtil.java

示例3: updatePromptLabelOnEDT

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
static void updatePromptLabelOnEDT(final JLabel label, final JTextComponent text) {
    String promptText = " ";
    if (!text.hasFocus() && "".equals(text.getText())) {
        final Object prompt = text.getClientProperty(PROMPT_KEY);
        if (prompt != null) promptText = prompt.toString();
    }
    label.setText(promptText);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:AquaTextFieldSearch.java

示例4: paintSafely

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
protected void paintSafely(Graphics g) {
    super.paintSafely(g);
    JTextComponent comp = getComponent();
    if(hint!=null && comp.getText().length() == 0 && (!(hideOnFocus && comp.hasFocus()))){
        if(color != null) {
            g.setColor(color);
        } else {
            g.setColor(comp.getForeground().brighter().brighter().brighter());
        }
        int padding = (comp.getHeight() - comp.getFont().getSize())/2;
        g.drawString(hint, 2, comp.getHeight()-padding-1);
    }
}
 
开发者ID:Joshuagollaher,项目名称:HawkEngine,代码行数:15,代码来源:TextFieldHint.java

示例5: selectAll

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * Selects all contents of a text component.
 *
 * @param textComponent
 */
public static void selectAll(JTextComponent textComponent) {
    if (!textComponent.hasFocus()) {
        textComponent.requestFocus();
    }
    textComponent.selectAll();
}
 
开发者ID:YcheCourseProject,项目名称:DIA-Umpire-Maven,代码行数:12,代码来源:TextComponentUtil.java

示例6: mousePressed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void mousePressed(MouseEvent evt) {
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("mousePressed: " + logMouseEvent(evt) + ", state=" + mouseState + '\n'); // NOI18N
    }

    JTextComponent c = component;
    if (c != null && isLeftMouseButtonExt(evt)) {
        // Expand fold if offset is in collapsed fold
        int offset = mouse2Offset(evt);
        switch (evt.getClickCount()) {
            case 1: // Single press
                if (c.isEnabled() && !c.hasFocus()) {
                    c.requestFocus();
                }
                c.setDragEnabled(true);
                if (evt.isShiftDown()) { // Select till offset
                    moveDot(offset);
                    adjustRectangularSelectionMouseX(evt.getX(), evt.getY()); // also fires state change
                    mouseState = MouseState.CHAR_SELECTION;
                } else { // Regular press
                    // check whether selection drag is possible
                    if (isDragPossible(evt) && mapDragOperationFromModifiers(evt) != TransferHandler.NONE) {
                        mouseState = MouseState.DRAG_SELECTION_POSSIBLE;
                    } else { // Drag not possible
                        mouseState = MouseState.CHAR_SELECTION;
                        setDot(offset);
                    }
                }
                break;

            case 2: // double-click => word selection
                mouseState = MouseState.WORD_SELECTION;
                // Disable drag which would otherwise occur when mouse would be over text
                c.setDragEnabled(false);
                // Check possible fold expansion
                try {
                    // hack, to get knowledge of possible expansion. Editor depends on Folding, so it's not really possible
                    // to have Folding depend on BaseCaret (= a cycle). If BaseCaret moves to editor.lib2, this contract
                    // can be formalized as an interface.
                    Callable<Boolean> cc = (Callable<Boolean>)c.getClientProperty("org.netbeans.api.fold.expander");
                    if (cc == null || !cc.equals(this)) {
                        if (selectWordAction == null) {
                            selectWordAction = ((BaseKit) c.getUI().getEditorKit(
                                    c)).getActionByName(BaseKit.selectWordAction);
                        }
                        if (selectWordAction != null) {
                            selectWordAction.actionPerformed(null);
                        }
                        // Select word action selects forward i.e. dot > mark
                        minSelectionStartOffset = getMark();
                        minSelectionEndOffset = getDot();
                    }
                } catch (Exception ex) {
                    Exceptions.printStackTrace(ex);
                }
                break;
                
            case 3: // triple-click => line selection
                mouseState = MouseState.LINE_SELECTION;
                // Disable drag which would otherwise occur when mouse would be over text
                c.setDragEnabled(false);
                if (selectLineAction == null) {
                    selectLineAction = ((BaseKit) c.getUI().getEditorKit(
                            c)).getActionByName(BaseKit.selectLineAction);
                }
                if (selectLineAction != null) {
                    selectLineAction.actionPerformed(null);
                    // Select word action selects forward i.e. dot > mark
                    minSelectionStartOffset = getMark();
                    minSelectionEndOffset = getDot();
                }
                break;

            default: // multi-click
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:79,代码来源:BaseCaret.java


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