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 下载并 ...
随机推荐
- Mac终端中主机名与用户名的修改
Mac终端的主机名称+用户名全部显示出来的话会可能显得特别长,影响整体美观,可以切换至root用户后 修改.bashrc文件进行格式化. 1. 终端中切换root用户 su - root 2. 修改/ ...
- c++ primer读书笔记之c++11(四)
1 带有作用域的枚举 scoped-enumeration 相信大家都用过枚举量,都是不带有作用域的,在头文件中定义需要特别注意不要出现重名的情况.为了解决这种问题,c++11提供了带作用于的枚举. ...
- 7款让人惊叹的HTML5粒子动画特效
HTML5的很大一个优势就是可以更加便捷高效地制作网页粒子动画特效,特别是Canvas特性,可以实现在网页上绘制任何图形和动画.本文要分享7款让人惊叹的HTML5粒子动画特效,这些粒子特效都提供源代码 ...
- 使用卷积神经网络CNN训练识别mnist
算的的上是自己搭建的第一个卷积神经网络.网络结构比较简单. 输入为单通道的mnist数据集.它是一张28*28,包含784个特征值的图片 我们第一层输入,使用5*5的卷积核进行卷积,输出32张特征图, ...
- python.pandas read and write CSV file
#read and write csv of pandasimport pandas as pd goog =pd.read_csv(r'C:\python\demo\LiaoXueFeng\data ...
- 最美应用API接口分析
最美应用API接口分析html, body {overflow-x: initial !important;}.CodeMirror { height: auto; } .CodeMirror-scr ...
- 了解PHP中$_SERVER变量对路径的解析
1,$_SERVER["QUERY_STRING"]说明:查询(query)的字符串 2,$_SERVER["REQUEST_URI"]说明:访问此页面所需的U ...
- 火狐FireFox看视频不能全屏显示的问题
问题:最大化/全屏时显示有问题,不能全屏显示,只能看到左上角一部分画面. 解决办法:在画面右键弹出的菜单中选择[设置]——勾选[启用硬件加速].
- C语言 · 筛选号码
算法训练 筛选号码 时间限制:1.0s 内存限制:512.0MB 问题描述 有n个人围成一圈,顺序排号(编号为1到n).从第1个人开始报数(从1到3报数),凡报到3的人退出圈子.从下 ...
- WCF安全:通过 扩展实现用户名密码认证
在webSservice时代,可以通过SOAPHEADER的方式很容易将用户名.密码附加到SOAP header消息头上,用户客户端对调用客户端身份的验证.在WCF 时代,也可以通过Operation ...