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


Java JTextField.getCaretPosition方法代码示例

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


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

示例1: keyPressed

import javax.swing.JTextField; //导入方法依赖的package包/类
@Override
public void keyPressed(KeyEvent ke) {
	
	int keyCode = ke.getKeyCode();
	Object keSource = ke.getSource();
	JTextField jTextField = (JTextField) keSource;;
	int caretPos = jTextField.getCaretPosition();
	int textLength = jTextField.getText().length();
	
	if(keyCode == KeyEvent.VK_ESCAPE){
		// Due to a java bug, the callback method is not called automatically when pressing escape.
		cancelCellEditing();
	} else if(keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_TAB){
		// Remember which key was used to confirm editing
		confirmationKey = keyCode;
	} else if(keyCode==KeyEvent.VK_RIGHT && caretPos==textLength){
		confirmationKey = keyCode;
		stopCellEditing();
	} else if(keyCode==KeyEvent.VK_LEFT && caretPos==0){
		confirmationKey = keyCode;
		stopCellEditing();
	}
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:24,代码来源:BasicCellEditor.java

示例2: isCompletionKey

import javax.swing.JTextField; //导入方法依赖的package包/类
private boolean isCompletionKey (int keyCode, JTextField textField) {
    if (keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_TAB) {
        return true;
    }
    if (keyCode == KeyEvent.VK_RIGHT && 
            (textField.getCaretPosition() >= (textField.getDocument().getLength() - 1))) {
        return true;
    }
    
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:FileCompletionPopup.java

示例3: keyTyped

import javax.swing.JTextField; //导入方法依赖的package包/类
public void keyTyped(KeyEvent kT) {

char charackter = kT.getKeyChar();
String singleChar = Character.toString(charackter);

JTextField displayField = (JTextField) kT.getComponent();
String currValue = displayField.getText();
int caretPosition = displayField.getCaretPosition();

// --- Allow negative values ------------------
if (this.isFloatValue==true) {
	// --- Float values -----------------------
	if (singleChar.equals("-") && countCharsInString(currValue, charackter)<2) {
		return;
	}
} else {
	// --- Integer values ---------------------
	if (singleChar.equals("-") && caretPosition==0 && currValue.startsWith("-")==false) {
		return;
	}
}

if (this.isFloatValue==true) {
	// --- Float values -----------------------
	if (singleChar.equals(".") || singleChar.equals(",")) {
		if (currValue!=null) {
			if (currValue.contains(".") || currValue.contains("," )) {
				kT.consume();	
				return;
			}
		}
	} else  if (singleChar.equalsIgnoreCase("e")) {
		if (currValue!=null) {
			if (currValue.contains("e")) {
				kT.consume();	
				return;
			}	
		}
	} else  if (singleChar.matches( "[0-9]" ) == false) {
		kT.consume();	
		return;
	}
	
} else {
	// --- Integer or Long values ---------------------
	if ( singleChar.matches( "[0-9]" ) == false ) {
		kT.consume();	
		return;
	}
	
} // --- end if -------------------------------

}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:54,代码来源:KeyAdapter4Numbers.java


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