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


Java JTextComponent.setSelectionEnd方法代码示例

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


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

示例1: setTextFieldValue

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void setTextFieldValue(String value, String projectValue, JTextComponent field) {
        if (value != null) {
            field.setText(value);
            component.setToolTipText(null);
            inherited = false;
            label.setFont(label.getFont().deriveFont(Font.BOLD));
        } else if (projectValue != null) {
            field.setText(projectValue);
            field.setSelectionEnd(projectValue.length());
            field.setSelectionStart(0);
//            field.setBackground(INHERITED);
            label.setFont(label.getFont().deriveFont(Font.PLAIN));
            component.setToolTipText(MSG_Value_Inherited());
            inherited = true;
        } else {
            field.setText("");//NOI18N
            component.setToolTipText(null);
            inherited = false;
            label.setFont(label.getFont().deriveFont(Font.BOLD));
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:TextComponentUpdater.java

示例2: insertSelectedChoice

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * Inserts the choice selected in the parameter choices window.
 *
 * @return Whether the choice was inserted.  This will be <code>false</code>
 *         if the window is not visible, or no choice is selected.
 */
boolean insertSelectedChoice() {
	if (paramChoicesWindow!=null && paramChoicesWindow.isVisible()) {
		String choice = paramChoicesWindow.getSelectedChoice();
		if (choice!=null) {
			JTextComponent tc = ac.getTextComponent();
			Highlight h = getCurrentParameterHighlight();
			if (h!=null) {
				 // "+1" is a workaround for Java Highlight issues.
				tc.setSelectionStart(h.getStartOffset()+1);
				tc.setSelectionEnd(h.getEndOffset());
				tc.replaceSelection(choice);
				moveToNextParam();
			}
			else {
				UIManager.getLookAndFeel().provideErrorFeedback(tc);
			}
			return true;
		}
	}
	return false;
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:28,代码来源:ParameterizedCompletionContext.java

示例3: prepareEditor

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void prepareEditor() {
    Component c = getEditor().getEditorComponent();

    if (c instanceof JTextComponent) {
        JTextComponent jtc = (JTextComponent) c;
        String s = jtc.getText();

        if ((s != null) && (s.length() > 0)) {
            jtc.setSelectionStart(0);
            jtc.setSelectionEnd(s.length());
        }

        if (tableUI) {
            jtc.setBackground(getBackground());
        } else {
            jtc.setBackground(PropUtils.getTextFieldBackground());
        }
        if( tableUI )
            jtc.requestFocus();
    }

    if (getLayout() != null) {
        getLayout().layoutContainer(this);
    }

    repaint();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:ComboInplaceEditor.java

示例4: replacePattern

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private static void replacePattern(String pattern, JTextComponent area, String replace, boolean select) {
    String props = area.getText();
    Matcher match = Pattern.compile(pattern, Pattern.DOTALL).matcher(props);
    if (match.matches()) {
        int begin = props.indexOf(TestChecker.PROP_SKIP_TEST);
        props = props.replace(TestChecker.PROP_SKIP_TEST + match.group(1), replace); //NOI18N
        area.setText(props);
        if (select) {
            area.setSelectionStart(begin);
            area.setSelectionEnd(begin + replace.length());
            area.requestFocusInWindow();
        }
    } else {
        String sep = "\n";//NOI18N
        if (props.endsWith("\n") || props.trim().length() == 0) {//NOI18N
            sep = "";//NOI18N
        }
        props = props + sep + replace; //NOI18N
        area.setText(props);
        if (select) {
            area.setSelectionStart(props.length() - replace.length());
            area.setSelectionEnd(props.length());
            area.requestFocusInWindow();
        }
    }

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:ActionMappings.java

示例5: moveToNextParam

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * Moves to and selects the next parameter.
 *
 * @see #moveToPreviousParam()
 */
private void moveToNextParam() {

	JTextComponent tc = ac.getTextComponent();
	int dot = tc.getCaretPosition();
	int tagCount = tags.size();
	if (tagCount==0) {
		tc.setCaretPosition(maxPos.getOffset());
		deactivate();
	}

	Highlight currentNext = null;
	int pos = -1;
	List<Highlight> highlights = getParameterHighlights();
	for (int i=0; i<highlights.size(); i++) {
		Highlight hl = highlights.get(i);
		// Check "< dot", not "<= dot" as OutlineHighlightPainter paints
		// starting at one char AFTER the highlight starts, to work around
		// Java issue.  Thanks to Matthew Adereth!
		if (currentNext==null || currentNext.getStartOffset()</*=*/dot ||
				(hl.getStartOffset()>dot &&
				hl.getStartOffset()<=currentNext.getStartOffset())) {
			currentNext = hl;
			pos = i;
		}
	}

	// No params after caret - go to first one
	if (currentNext.getStartOffset()+1<=dot) {
		int nextIndex = getFirstHighlight(highlights);
		currentNext = highlights.get(nextIndex);
		pos = 0;
	}

	// "+1" is a workaround for Java Highlight issues.
	tc.setSelectionStart(currentNext.getStartOffset()+1);
	tc.setSelectionEnd(currentNext.getEndOffset());
	updateToolTipText(pos);

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:45,代码来源:ParameterizedCompletionContext.java

示例6: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
    if (ignoreComboAction)
        return; // not invoked by user, ignore

    GuardedBlock gBlock = codeData.getGuardedBlock(category, blockIndex);
    GuardBlockInfo gInfo = getGuardInfos(category)[blockIndex];
    int[] blockBounds = getGuardBlockBounds(category, blockIndex);
    int startOffset = blockBounds[0];
    int endOffset = blockBounds[1];
    int gHead = gBlock.getHeaderLength();
    int gFoot = gBlock.getFooterLength();
    JTextComponent editor = getEditor(category);
    StyledDocument doc = (StyledDocument) editor.getDocument();

    changed = true;

    JComboBox combo = (JComboBox) e.getSource();
    try {
        docListener.setActive(false);
        if (combo.getSelectedIndex() == 1) { // changing from default to custom
            NbDocument.unmarkGuarded(doc, startOffset, endOffset - startOffset);
            // keep last '\n' so we don't destroy next editable block's position
            doc.remove(startOffset, endOffset - startOffset - 1);
            // insert the custom code into the document
            String customCode = gBlock.getCustomCode();
            int customLength = customCode.length();
            if (gInfo.customizedCode != null) { // already was edited before
                customCode = customCode.substring(0, gHead)
                             + gInfo.customizedCode
                             + customCode.substring(customLength - gFoot);
                customLength = customCode.length();
            }
            if (customCode.endsWith("\n")) // NOI18N
                customCode = customCode.substring(0, customLength-1);
            doc.insertString(startOffset, customCode, null);
            gInfo.customized = true;
            // make guarded "header" and "footer", select the text in between
            NbDocument.markGuarded(doc, startOffset, gHead);
            NbDocument.markGuarded(doc, startOffset + customLength - gFoot, gFoot);
            editor.setSelectionStart(startOffset + gHead);
            editor.setSelectionEnd(startOffset + customLength - gFoot);
            editor.requestFocus();
            combo.setToolTipText(gBlock.getCustomEntry().getToolTipText());
        }
        else { // changing from custom to default
            // remember the customized code
            gInfo.customizedCode = doc.getText(startOffset + gHead,
                                               endOffset - gFoot - gHead - startOffset);
            NbDocument.unmarkGuarded(doc, endOffset - gFoot, gFoot);
            NbDocument.unmarkGuarded(doc, startOffset, gHead);
            // keep last '\n' so we don't destroy next editable block's position
            doc.remove(startOffset, endOffset - startOffset - 1);
            String defaultCode = gBlock.getDefaultCode();
            if (defaultCode.endsWith("\n")) // NOI18N
                defaultCode = defaultCode.substring(0, defaultCode.length()-1);
            doc.insertString(startOffset, defaultCode, null);
            gInfo.customized = false;
            // make the whole text guarded, cancel selection
            NbDocument.markGuarded(doc, startOffset, defaultCode.length()+1); // including '\n'
            if (editor.getSelectionStart() >= startOffset && editor.getSelectionEnd() <= endOffset)
                editor.setCaretPosition(startOffset);
            combo.setToolTipText(NbBundle.getMessage(CustomCodeData.class, "CTL_GuardCombo_Default_Hint")); // NOI18N
        }
        // we must create a new Position - current was moved away by inserting new string on it
        gInfo.position = NbDocument.createPosition(doc, startOffset, Position.Bias.Forward);

        docListener.setActive(true);
    }
    catch (BadLocationException ex) { // should not happen
        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:74,代码来源:CustomCodeView.java

示例7: comment

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void comment(JTextComponent target, BaseDocument doc, CommentHandler commentHandler, int[] comments, int from, int to, boolean lineSelection) throws BadLocationException {
//        System.out.println("comment");

        int diff = 0;
        String startDelim = commentHandler.getCommentStartDelimiter();
        String endDelim = commentHandler.getCommentEndDelimiter();

        //put the comment start
        boolean startInComment = false;
        
        if (comments.length > 0) {
            int cStart = comments[0];
            int cEnd = comments[1];
            
            if (cStart <= from && cEnd > from) {
                // the to-be-commented area starts in this comment
                startInComment = true;
            }
        }
        if (!startInComment) {
            // insert start comment mark
            diff += insert(doc, from, startDelim);
        }

        for (int i = 0; i < comments.length; i += 2) {
            int commentStart = comments[i];
            int commentEnd = comments[i + 1];
            if (commentStart >= from) {
                diff += remove(doc, commentStart + diff, startDelim.length());
            }

            if (commentEnd <= to) {
                diff += remove(doc, commentEnd + diff - endDelim.length(), endDelim.length());
            }

        }

        //add closing comment if the last comment doesn't contain the 'to' offset
        if (comments.length == 0 || comments[comments.length - 1] <= to) {
            diff += insert(doc, to + diff, endDelim);
        }

        if (!lineSelection) {
            //update the selection range, we always add the starting delimiter out of the selection
            target.setSelectionStart(from);
            target.setSelectionEnd(to + diff);
        }

    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:50,代码来源:ToggleBlockCommentAction.java

示例8: moveToPreviousParam

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * Moves to and selects the previous parameter.
 *
 * @see #moveToNextParam()
 */
private void moveToPreviousParam() {

	JTextComponent tc = ac.getTextComponent();

	int tagCount = tags.size();
	if (tagCount==0) { // Should never happen
		tc.setCaretPosition(maxPos.getOffset());
		deactivate();
	}

	int dot = tc.getCaretPosition();
	int selStart = tc.getSelectionStart()-1; // Workaround for Java Highlight issues.
	Highlight currentPrev = null;
	int pos = 0;
	List<Highlight> highlights = getParameterHighlights();

	for (int i=0; i<highlights.size(); i++) {
		Highlight h = highlights.get(i);
		if (currentPrev==null || currentPrev.getStartOffset()>=dot ||
				(h.getStartOffset()<selStart &&
				(h.getStartOffset()>currentPrev.getStartOffset() ||
						pos==lastSelectedParam))) {
			currentPrev = h;
			pos = i;
		}
	}

	// Loop back from param 0 to last param.
	int firstIndex = getFirstHighlight(highlights);
	//if (pos==0 && lastSelectedParam==0 && highlights.size()>1) {
	if (pos==firstIndex && lastSelectedParam==firstIndex && highlights.size()>1) {
		pos = getLastHighlight(highlights);
		currentPrev = highlights.get(pos);
		 // "+1" is a workaround for Java Highlight issues.
		tc.setSelectionStart(currentPrev.getStartOffset()+1);
		tc.setSelectionEnd(currentPrev.getEndOffset());
		updateToolTipText(pos);
	}
	else if (currentPrev!=null && dot>currentPrev.getStartOffset()) {
		 // "+1" is a workaround for Java Highlight issues.
		tc.setSelectionStart(currentPrev.getStartOffset()+1);
		tc.setSelectionEnd(currentPrev.getEndOffset());
		updateToolTipText(pos);
	}
	else {
		tc.setCaretPosition(maxPos.getOffset());
		deactivate();
	}

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:56,代码来源:ParameterizedCompletionContext.java


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