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 ... 
随机推荐
- 安全管理中心(SOC)引导企业信息安全建设的思路
			SOC即企业安全管理中心,该模型可帮助企业信息安全人员在进行安全建设方面提供整体性的参考.如下所示,以下模型分为数据采集部分收集了各类设备及日志等数据,这些数据收集到了以后提供给SOC安全管理中心,而 ... 
- ASP.NET MVC 部分视图
			[部分视图] ASP.NET MVC 里的部分视图,相当于 Web Form 里的 User Control.我们的页面往往会有许多重用的地方,可以进行封装重用.使用 部分视图 : 1. 可以简写代 ... 
- 【嵌入式】S3C2410平台移植linux 2.6.14内核
			小续 第一次接触内核的东西,有点小激动啊 激动归激动,这实验还是要继续做下去,书上三两句话就带过去的,剩下的就留给我们了,着实考验动手能力啊 当编译过内核之后,发现这个过程也不复杂嘛(复杂的是内核的配 ... 
- css基础 -文本溢出 text-overflow:ellipsis;
			.className{overflow:hidden;white-space:nowrap;text-overflow:ellipsis;} 外部结构如下是就失效了:(移动端) <a class ... 
- stopManagedWebLogic.sh强制关闭Managed Server
			Adding force shutdown of managed server in weblogic. ----------------------------------------------- ... 
- Office 2010 激活 - Failed to inject memory!
			是不是用了mini-KMS_Activator这个工具去激活?是的话,把mini-KMS_Activator点出来,使用第一个按钮Install / Uninstall KM Service把它的服务 ... 
- RabbitMQ中各种消息类型如何处理?
			一:消息类型 Map String(含json字符串类型) 二:处理方法 2.1 Map消息 如果发送的消息类型是map类型,可以通过SerializationUtils.deserialize方法将 ... 
- C#学习笔记(7)——委托
			说明(2017-5-29 22:22:50): 1. 语法:public delegate void mydel();这一句在类外面,命名空间里面. 2. 专门新建一个方法,参数是委托: public ... 
- 基于css3 transform实现散乱的照片排列
			分享一款基于css3 transform实现散乱的照片排列.这是一款简单零散的css3相册排列特效下载.效果图如下: 在线预览 源码下载 实现的代码. html代码: <div class= ... 
- C#生成DLL,在Unity中导入/调用DLL
			网上搜了一些DLL的创建.编写.使用的学习资料,感觉比较的凌乱.或是复杂抽象,或是关键地方一笔带过,不是很适合萌新.于是决定还是图文记录一下该过程,尽量精简而又明确. 学习资料: https://do ... 
