e612. Moving the Focus to the Next or Previous Focusable Component
The methods to move the focus to the next or to the previous focusable component are Component.transferFocus() and Component.transferFocusBackward().
This example modifies a component so that pressing the space bar or pressing F2 moves the focus to the next focusable component. Pressing shift space or shift F2 moves the focus to the previous focusable component.
// Bind space and shift space
component.getInputMap(JComponent.WHEN_FOCUSED).put(
KeyStroke.getKeyStroke("SPACE"), nextFocusAction.getValue(Action.NAME));
component.getInputMap(JComponent.WHEN_FOCUSED).put(
KeyStroke.getKeyStroke("shift SPACE"), prevFocusAction.getValue(Action.NAME)); // This key binding is required for text components. It hides the
// default typed space key binding in a text component. If you don't
// hide this key binding, typing the space key will insert a space into
// the text component (as well as move the focus).
// See e1003 覆盖一些和JTextComponent绑定的键 for more details.
component.getInputMap(JComponent.WHEN_FOCUSED).put(
KeyStroke.getKeyStroke(new Character(' '), 0), "unbound"); // Bind F2 and shift F2
component.getInputMap(JComponent.WHEN_FOCUSED).put(
KeyStroke.getKeyStroke("F2"), nextFocusAction.getValue(Action.NAME));
component.getInputMap(JComponent.WHEN_FOCUSED).put(
KeyStroke.getKeyStroke("shift F2"), prevFocusAction.getValue(Action.NAME)); // Add actions
component.getActionMap().put(nextFocusAction.getValue(Action.NAME), nextFocusAction);
component.getActionMap().put(prevFocusAction.getValue(Action.NAME), prevFocusAction); // The actions
public Action nextFocusAction = new AbstractAction("Move Focus Forwards") {
public void actionPerformed(ActionEvent evt) {
((Component)evt.getSource()).transferFocus();
}
};
public Action prevFocusAction = new AbstractAction("Move Focus Backwards") {
public void actionPerformed(ActionEvent evt) {
((Component)evt.getSource()).transferFocusBackward();
}
};
| Related Examples |
e612. Moving the Focus to the Next or Previous Focusable Component的更多相关文章
- View Focus的处理过程及ViewGroup的mFocused字段分析
通过上篇的介绍,我们知道在对KeyEvent的处理中有非常重要的一环,那就是KeyEvent在focus view的path上自上而下的分发, 换句话说只有focus的view才有资格参与KeyEve ...
- e617. Determining the Opposite Component of a Focus Event
The opposite component is the other component affected in a focus event. Specifically, in a focus-lo ...
- e616. Determining If a Focus Lost Is Temporary or Permanent
A temporary focus-lost event occurs if the focus moves to another window. It's temporary because the ...
- Selenium Webdriver概述(转)
Selenium Webdriver https://www.yiibai.com/selenium/selenium_overview.html# webdriver自动化俗称Selenium 2. ...
- roundabout旋转幻灯
jquery.roundabout.js文件/** * jQuery Roundabout - v2.4.2 * http://fredhq.com/projects/roundabout * * M ...
- 阻尼滑动--能够滑动过度的ScrollView(OverScrollView)
贴上一个我自己用过的阻尼滑动的ScrollView,像QQ里面那种滑动效果,尽管不是我写的,可是我认为还能够,贴出来做个记录,实用到的时候免得到处去找. 代码例如以下: /* * Copyright ...
- Android 继承framelayout,实现ScrollView 和 HorizontalScrollView 的效果
有些项目,需要让控件或者布局进行水平和垂直同时能拖拽,当然,ScrollView 和 HorizontalScrollView 的结合写法是一种写法.但是,这么写用户体验效果不佳,会有迟钝感,因此推荐 ...
- Android--ScrollView边界回弹效果
/* * Copyright (C) 2006 The Android Open Source Project * * Licensed under the Apache License, Versi ...
- Selenium浏览器自动化测试使用(2)
Selenium - 环境安装设置 为了开发Selenium RC或webdriver脚本,用户必须确保他们有初始配置完成.有很多关联建立环境的步骤.这里将通过详细的讲解. 下载并安装Java 下载并 ...
随机推荐
- TCP三次握手,四次分手
1.什么是HTTP连接 http是建立在TCP协议之上的一种应用. 最显著的特点是每次请求,都需要服务器响应,请求结束后,会主动释放连接. 1)在HTTP 1.0中,客户端的每次请求都要建立一次单独的 ...
- 【Windows】windows核心编程整理(上)
小续 这是我11年看<windows核心编程>时所作的一些笔记,现整理出来共享给大家 windows核心编程整理(上) windows核心编程整理(下) 线程的基础知识 进程是不活泼的,进 ...
- 【Socket】linux高性能网络服务程序
1.mystery引入 1)高性能的网络服务程序分为单线程重复式网络服务.多进程网络服务 .多线程网络服务.线程池网络服务和IO多路复用网络服务等 2)单线程重复式是最基本的一种TCP服务模式,其实现 ...
- ZendStudio在kali下无法启动
错误如下 # # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0 ...
- vjue 点击发送邮件如何处理
<li @click.stop="openSendMail()"> <i class="icons mail-icon" title=&quo ...
- Openfire注册流程代码分析
Openfire注册流程代码分析 一.客户端/服务端注册用户流程 经过主机连接消息确认后,客户端共发送俩条XML完成注册过程.服务器返回两条XML. 注:IQ消息节点用于处理用户的注册.好友.分组.获 ...
- linux下文件描述符的查看及分析
起因 近期在调试一个Android播放内核是遇到上层传递的是fd(file descriptor),但是在文件播放结束之后调用lseek却提示返回-1,errno=29(#define ESPIPE ...
- Makefile常用万能模板(包括静态链接库、动态链接库、可执行文件)
本文把makefile 分成了三份:生成可执行文件的makefile,生成静态链接库的makefile,生成动态链接库的makefile. 这些makefile都很简单,一般都是一看就会用,用法也很容 ...
- js实现上传图片本地预览功能以及限制图片的文件大小和尺寸大小
方法一: js: /** * 上传图片本地预览方法 * @param {Object} fileObj 上传文件file的id元素 fresh-fileToUpload * ...
- 4. 集成学习(Ensemble Learning)Adaboost
1. 集成学习(Ensemble Learning)原理 2. 集成学习(Ensemble Learning)Bagging 3. 集成学习(Ensemble Learning)随机森林(Random ...