當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。