⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 autotextfield.java

📁 CRMS客户关系管理系统(JAVA版),这是一个客户关系管理系统。
💻 JAVA
字号:
package crms.ui;import java.util.*;import javax.swing.*;import java.awt.event.*;public class AutoTextField extends JTextField implements KeyListener {	public static final int DEFAULT_MIN_COMPARE_LENGTH = 2;	protected List search_list = null;	protected int min_compare_length = DEFAULT_MIN_COMPARE_LENGTH;	protected boolean automatic = false;	protected boolean completeEnabled = true;	public AutoTextField() {		this(null, DEFAULT_MIN_COMPARE_LENGTH);	}	public AutoTextField(List search_list, int min_compare_length) {		super();		this.addKeyListener( this );		setSearchList(search_list);	}	// property functions	public void setSearchList(List new_list) {		search_list = new_list;		/*		System.out.println("Found staff:");		for (int i=0; i < search_list.size(); i++)			System.out.println(search_list.get(i));		*/	}	public List getSearchList() {		return search_list;	}	public void setMinCompareLength(int new_length) {		min_compare_length = new_length;	}	public int getMinCompareLength() {		return min_compare_length;	}	/** Determine whether the current text display has been automatically completed 	 *	 * @return Current automatic completion status     */	public boolean isAutomatic() {		return automatic;	}	protected void autoComplete(String search) {		if (search_list == null) { return; }		if (search.length() < min_compare_length) { return; } 		//completeEnabled = false;		for (int i = 0; i < search_list.size(); i++) {			String compare = (String)search_list.get(i);			if (compare.startsWith(search)) {				int cpos = search.length();				setText(compare);				setCaretPosition(cpos);				setSelectionStart(cpos);				setSelectionEnd(compare.length());				automatic = true;				break;			}		}		//completeEnabled = true;	}			// required functions to satisfy the KeyListener class	public void keyTyped(KeyEvent e) { }	/** Handle the key press event, invalidating the auto completion status.  This is significant	 * if you are trying to determine whether or not the current text is automatic or not.	 * The logic here is that if the user has pressed a key then it is no longer under automatic control.	 */	public void keyPressed(KeyEvent e) { 		automatic = false;	}	// trigger off the auto complete search function	public void keyReleased(KeyEvent e) { 		char c = e.getKeyChar();		if (completeEnabled && (Character.isDigit(c) || Character.isLetter(c))) {			// only allow up to selection start for the compare characters			// fixes bug where the user types really quickly			String search = this.getText().substring(0, getSelectionStart());			autoComplete(search);		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -