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 ...
随机推荐
- Multi-cloud Kubernetes with Triton
https://www.joyent.com/blog/triton-kubernetes-multicloud While running an experimental Kubernetes cl ...
- VS2015打开项目慢、死机和卡顿解决方案
VS2015功能强大,但是经常慢 网上有解决方案如下几个,留着备用: 1.选项-环境-基于客户端性能自动调整视觉体验,去掉选项. 2.选项-源代码管理-插件选无. 3.选项-文本编辑器-所有语言-滚动 ...
- Android下基于SDL的位图渲染(一)
环境准备 安装Android开发环境(java.android-sdk.android ndk.gcc). 我使用的ndk版本是r10b/r10d,在win10/ubutu 15.04编译 下载sdl ...
- Excel中功能清单转Project任务
接:http://www.cnblogs.com/vipsoft/p/8495220.html 1.在E列输入公式: =IF(LEN(A2)>1,1,IF(LEN(B2)>1,2,IF(L ...
- ios xib和代码的frame布局 iOSXib布局后代码修改约束的值
如何修改autolayout 约束的值? 1 2 3 4 5 6 目前我已知的方法有5种 1.修改frame(有时候可能会不起作用,但可以做动画) 2.修改约束的float值 3.使用VisualFo ...
- python json (loads(),load(),jump(),jumps())
# loads() str to json data# jumps() json to str# jump() json to filedef ladstest(): data = '{"n ...
- Android Toolbar的使用 顶部标题栏+后退键
最近设计安卓里面有个标题栏,里面有个后退键,可以完成后退之类的功能. 好,刚好可以用Toolbar去实现 上代码:activity_main.xml <?xml version="1. ...
- [转]关于setInterval只执行一次的原因
原文地址:https://blog.csdn.net/skyblacktoday/article/details/79374613 我在做一个demo的时候发现的,之前可能遇到过到时没有记住,也没有写 ...
- asp.net gridview 如何实现行点击事件
第一步:绑定行点击事件 protected void GV_DATA_RowDataBound( object sender, GridViewRowEventArgs e ) { if( e.Row ...
- pip修改国内源
Linux在~/.pip/pip.conf文件中添加或修改, windows不存在该目录,在当前用户目录下创建pip.ini(例如 C:\Users\bin\pip\pip.ini): [global ...