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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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) ...

  5. 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 ...

  6. cvpr2015papers

    @http://www-cs-faculty.stanford.edu/people/karpathy/cvpr2015papers/ CVPR 2015 papers (in nicer forma ...

  7. 提高神经网络的学习方式Improving the way neural networks learn

    When a golf player is first learning to play golf, they usually spend most of their time developing ...

  8. PA教材提纲 TAW12-2

    Unit1 Adjustment of SAP Standard Software(SAP标准软件修改) 1.1 Adjusting SAP Standard Software(如何修改SAP标准软件 ...

  9. tmux手册中文翻译

    man tmux可以看到最详细的tmux介绍,本文翻译自tmux手册. tmux全名叫"terminal multiplexer",终端多路复用器. tmux的命令格式为: tmu ...

随机推荐

  1. VLAN,GRE,VXLAN

    https://www.cnblogs.com/charles1ee/p/6629009.html VLAN介绍 局域网LAN(多个机器连接一个Hub或者Switch),是一个广播域 VLAN:一台S ...

  2. .NET CORE EF 框架调用存储过程

    ; //多个参数多表组合值 SqlParameter[] Param = { new SqlParameter("@UserId", System.Data.SqlDbType.V ...

  3. VS2015终极卸载方法

    今天打开VS2015发现出问题了,总是停止响应,去控制面板里卸载结果像下面这样,卸载出错!于是我有开始折腾了,重新安装一遍然后,还是有问题,在卸载还是出错于是我决定通过安装介质卸载,结果,悲剧的是,启 ...

  4. js使用正则表达式实现文本框只能输入数字和小数点

    第一种情况:且限制小数点前最大3位数,小数点后最大3为三位 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN& ...

  5. 在Jenkins上做一个定时闹钟

    [本文出自天外归云的博客园] 利用Jenkins定时任务来做一个闹钟,每天隔一段时间提醒自己一下“你该休息了!别老坐着!出去走一走!珍爱生命,远离久坐!” 首先在Jenkins上创建一个node. 创 ...

  6. 引用Interop.SQLDMO.dll后的注意事项。

    SQLDMO.dll是个好东西,ASP.NET利用它可以实现在线备份.还原数据库等各种功能.近日有客户要求为其在后台添加一个管理数据库的功能.于是就出现了这篇文章.     由于客户的数据库和WEB服 ...

  7. [转]Linux 命令行快捷键

    群里有人问"问个问题,Linux 命令行有没有快捷键一下从行末会到行头?经常敲了很多命令发现忘加 sudo 了,然后把命令删了重新敲一遍". 自己还真不知道怎么操作,只知道历史命令 ...

  8. jquery笔记一——小问题+小技巧

    1.table行单击选中radio(传说中input[type=radio]比input:radio要快) <tr class="rowSelect"> <td& ...

  9. Pycharm Professional破解(windows,mac)

    激活码 EB101IWSWD-eyJsaWNlbnNlSWQiOiJFQjEwMUlXU1dEIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYXNzaWduZWVOYW1lI ...

  10. ansible示例,离线安装etcd

    一.基础介绍 ========================================================================================== 1. ...