TestField设置长度
来源:互联网 发布:现在最红网络的游戏 编辑:程序博客网 时间:2024/06/16 15:07
import java.awt.BorderLayout;import java.awt.event.KeyAdapter;import java.awt.event.KeyEvent;import javax.swing.JTextField;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;public class TextFieldTest extends javax.swing.JFrame { private JTextField field; /** * Auto-generated main method to display this JFrame */ public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { TextFieldTest inst = new TextFieldTest(); inst.setLocationRelativeTo(null); inst.setVisible(true); } }); } public TextFieldTest() { super(); initGUI(); } private void initGUI() { try { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); { field = new LimitedTextField(); getContentPane().add(field, BorderLayout.CENTER); } pack(); this.setSize(400, 70); } catch (Exception e) { e.printStackTrace(); } } class LimitedTextField extends JTextField { private int maxLength = 5; public void setMaxLength(int maxLength) { this.maxLength = maxLength; } public int getMaxLength() { return this.maxLength; } public LimitedTextField() { this.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { int code = e.getKeyChar(); /*if (code == KeyEvent.VK_BACK_SPACE) { e.isActionKey(); } else*/ if (getDocument().getLength() >= maxLength) { e.consume(); } } }); } }}
0 0
- TestField设置长度
- UI常用控件UILabel、TestField
- CRichEditCtrl 设置字符长度
- vi设置tab长度
- 设置EditText的长度
- 代码设置EditText 长度
- 设置EditText 长度
- 设置输入框长度
- 移位寄存器设置移位长度
- TabLayout设置指示器长度
- 数组动态设置长度
- [记录]多个TestField切换光标
- 设置GridView编辑框长度
- 设置GridView编辑框长度
- 设置最短密码长度
- 设置下拉菜单的长度
- 设置输入框长度限制。
- html 设置span的长度
- Theaon:theaon的图结构
- soj 3014: Seek the Name, Seek the Fame (字符串hash)
- win7 64编译64位boost
- 平台顺利通过公安部一所《GBT 28181-2011 安全防范视频监控联网系统信息传输、交换、控制技术要求》检测
- Bozosort: Sorting by Exchanging
- TestField设置长度
- 已知keystore和密码,求alias
- android某加固脱壳(一)
- LeetCode(129) Sum Root to Leaf Numbers
- Testing Round #12
- BFS DFS
- Unix学习笔记-----编程练习实例------使用vfork&&execv()在程序中加载可执行程序
- IOS Iphone 6 以及Iphone6 Plus 屏幕的适配
- 大神文章系列链接