e614. Setting the Initial Focused Component in a Window
There is no straightforward way to set the initial focused component in a window. The typical method is to add a window listener to listen for the window opened event and then make the desired component request the focus.
// Create frame and three buttons
JFrame frame = new JFrame();
JButton component1 = new JButton("1");
JButton component2 = new JButton("2");
JButton component3 = new JButton("3"); // Set component with initial focus; must be done before the frame is made visible
InitialFocusSetter.setInitialFocus(frame, component2); class InitialFocusSetter {
public static void setInitialFocus(Window w, Component c) {
w.addWindowListener(new FocusSetter(c));
} public static class FocusSetter extends WindowAdapter {
Component initComp;
FocusSetter(Component c) {
initComp = c;
}
public void windowOpened(WindowEvent e) {
initComp.requestFocus(); // Since this listener is no longer needed, remove it
e.getWindow().removeWindowListener(this);
}
}
}
| Related Examples |
e614. Setting the Initial Focused Component in a Window的更多相关文章
- e636. Listening to All Key Events Before Delivery to Focused Component
Registering a key event dispatcher with the keyboard focus manager allows you to see all key events ...
- e620. Activating a Keystroke When Any Component in the Window Has Focus
Normally, a keystroke registered to a component is activated when the component has the focus. This ...
- How a non-windowed component can receive messages from Windows -- AllocateHWnd
http://www.delphidabbler.com/articles?article=1 Why do it? Sometimes we need a non-windowed componen ...
- How a non-windowed component can receive messages from Windows
Why do it? Sometimes we need a non-windowed component (i.e. one that isn't derived fromTWinControl) ...
- e621. Activating a Keystroke When Any Child Component Has Focus
Normally, a keystroke registered on a component is activated when the component has the focus. This ...
- cvpr2015papers
@http://www-cs-faculty.stanford.edu/people/karpathy/cvpr2015papers/ CVPR 2015 papers (in nicer forma ...
- 提高神经网络的学习方式Improving the way neural networks learn
When a golf player is first learning to play golf, they usually spend most of their time developing ...
- PA教材提纲 TAW12-2
Unit1 Adjustment of SAP Standard Software(SAP标准软件修改) 1.1 Adjusting SAP Standard Software(如何修改SAP标准软件 ...
- tmux手册中文翻译
man tmux可以看到最详细的tmux介绍,本文翻译自tmux手册. tmux全名叫"terminal multiplexer",终端多路复用器. tmux的命令格式为: tmu ...
随机推荐
- vim中权限不足时不用退出而强制保存
命令: :w !sudo tee % 此命令是把当前文件(即%)作为stdin传给sudo tee命令来执行.说起来挺绕口,其实就是:用sudo强制保存. 有时候在自己机器上折腾的时候需要更改一些 ...
- ny24 素数距离的问题 筛选法求素数
素数距离问题时间限制:3000 ms | 内存限制:65535 KB难度:2 描述 现在给出你一些数,要求你写出一个程序,输出这些整数相邻最近的素数,并输出其相距长度.如果左右有等距离长度素 ...
- 【设计模式】适配器模式与Reader、InputStream之间的适配
简述 适配器模式,目的是将A对象通过适配.转换的方式转换成B对象来使用,为什么转换为B对象?因为用户通过依赖B对象来使用. 适配器的实现有两种方式. 继承实现 组合实现 基于Java单继承的机制,组合 ...
- 关于 android receiver
可以在代码文件中声明一个receiver,也可以在manifest中声明一个,前者中的receiver只有在该activity launch起来以后才会监听其所感兴趣的事件,而如果在androidMa ...
- 19、UWP 新特性(Creator Update)
Build 版本 15063+ 1.能够为 CompositionObjects 的其他属性(阴影,裁剪,属性集合)添加动画 2.当设备插上电源的时候,通过 Extended Excution Ses ...
- Linux下双网卡绑定bond0【转】
一:原理: linux操作系统下双网卡绑定有七种模式.现在一般的企业都会使用双网卡接入,这样既能添加网络带宽,同时又能做相应的冗余,可以说是好处多多.而一般企业都会使用linux操作系统下自带的网卡绑 ...
- Oracle XQuery 过滤XML查询SQL
Oralce 支持SQL XQuery查询 一个简单示例: SELECT XMLQuery('for $i in /Videogame return $i/Type' passing by value ...
- centos 配置subversion svn
Subversion是一个自由,开源的版本控制系统. 1.安装: yum install subversion 2.配置 mkdir -p /var/svn/svnrepos #新建文件夹 svnad ...
- jquery开发的”天才笨笨碰“游戏
前段时间湖南卫视的快乐大本营里有一款“天才笨笨碰”游戏非常火.这款游戏主要是考选手的声母联想词语的能力. 小篇在看完这个节目后用jquery制作了“天才笨笨碰”网页游戏.先上效果图: 游戏规则: 1. ...
- Error: failure: repodata/repomd.xml from fedora: [Errno 256] No more mirrors to try.
记录一个小问题,重新买的linux换yum源的时候一直提示: Error: failure: repodata/repomd.xml ] No more mirrors to try. 一直说那个XM ...