【发布时间】:2012-06-05 04:55:27
【问题描述】:
我有一个简单的(不是?)问题,即在处理 JTable 后将焦点放在 JInternalFrame 上。
//I created a table, set it to visible, gave it focus.
list.dispose(); //I did what I wanted with the table and I dispose of it
screen.setVisible(true); //The screen is already visible. this isn't really needed
//After I closed table, I want the focus return to the screen (JInternalFrame)
screen.setFocusable(true);
screen.requestFocus();
screen.requestFocusInWindow();
screen.requestFocus(true);
desktopPane.setSelectedFrame(screen);
所以发生的事情是这样的:屏幕确实获得了焦点,从某种意义上说,当我检查哪个组件有焦点时 - 它确实返回了我 - 屏幕。但是顶部的栏(不确定此处的术语是否正确)包含图标、标题、X 的栏是灰色而不是蓝色。
知道如何使 JInternalFrame 看起来活跃,而不仅仅是表现活跃吗?
示例:http://nexrem.com/projects/FocusDemo.rar 我在 NetBeans 中快速完成了此操作,您所做的是:
点击打开screen1。它打开并集中。单击以打开 JTable。它打开并具有焦点。 Screen1 失去焦点。按 Esc 关闭 JInternalFrame。它关闭了,但 screen1 似乎没有焦点(至少在视觉上)。我怀疑它可能与焦点循环有关,因为它在 2 个 JInternalFrames 之间......
【问题讨论】:
-
如果在事件线程上排队请求呢?此外,如果您没有很快得到正确的答案,请考虑创建并发布sscce。
-
@HovercraftFullOfEels 不完全确定如何按照您的要求进行操作,但我已经编辑了我的帖子以包含指向我的 NetBeans 项目的链接。我做了一个快速干净的演示。
标签: java swing focus jcomponent jinternalframe