如何根据双击 JTable 的位置生成新面板?

发布于 2024-08-17 04:56:35 字数 323 浏览 5 评论 0原文

我需要帮助实现以下行为:当用户双击 JPanel A 上的 JTable 中的一行(如下所示的代码片段)时,程序应重定向用户访问 JPanel B。B 应该包含一些有关 JTable 行上的内容的数据。

private void TableMouseClicked(java.awt.event.MouseEvent evt) {
if(evt.getClickCount() == 2){
   System.out.println("Double click");
}
}

I need help implementing the following behavior: when a user double-clicks on a row in the JTable on JPanel A — code snippet for this shown below — the program should redirect the user to JPanel B. B should contain some data about whatever was on the JTable's row.

private void TableMouseClicked(java.awt.event.MouseEvent evt) {
if(evt.getClickCount() == 2){
   System.out.println("Double click");
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱她像谁 2024-08-24 04:56:35

“将用户重定向到”是什么意思?

如果另一个面板已经可见,您可以在第二个面板上使用 setFocus() 切换焦点(尽管这是一个有点不寻常的行为,可能会让您的用户感到惊讶)。

如果另一个面板不可见,但在 GUI 中有自己的空间,那么我想您只需将其设置为可见即可。如果它必须覆盖用户刚刚单击的面板,那么您需要使用 CardLayout 在同一空间中交替显示两个面板。

What do you mean, "redirect the user to?"

If the other panel is already visible, you can switch the focus there (though that's a bit unusual behavior which may negatively surprise your user) using setFocus() on the second panel.

If the other panel is not visible but has its own space in the GUI, then I guess you'd simply make it visible. If it has to overlay the panel the user just clicked on, then you want to use a CardLayout to display two panels alternatively in the same space.

你在看孤独的风景 2024-08-24 04:56:35

查看此线程: http://forums.sun.com/thread.jspa?threadID =366670
这本质上与您尝试做的事情相同,您只想响应鼠标双击而不是鼠标移动事件。

Check out this thread: http://forums.sun.com/thread.jspa?threadID=366670
This is essentially the same thing you are trying to do, you just want to respond to mouse double-clicks instead of mouse move events.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文