making a JPanel into a JOptionPane.OK_OPTION(将 JPanel 变成 JOptionPane.OK_OPTION)
问题描述
目前我有一个扩展 JPanel 的类,基本上显示了有关传递给其构造函数的对象的一些信息.屏幕上有各种标签和图像图标,并设置了 BorderLayout.
currently i have a class which extends JPanel and basically shows some information about an object passed into its constructor. There are various labels and Image icons on the screen and has a BorderLayout set.
当用户在主 GUI 中左键单击 ImageIcon 并显示在屏幕上时,将触发此面板.
This panel is triggered when the user left clicks on an ImageIcon from the main GUI and shows up on the screen.
我想知道,我如何(如果有办法)将 JOptionPane.OK_OPTION 实现到整个面板上,这样我就不必使用事件处理关闭面板,因为屏幕只是显示信息以及何时用户已完成,他们按 OK,面板应关闭.
i was wondering, how (if there is a way) i could implement the JOptionPane.OK_OPTION onto the whole Panel so that i dont have to close the panel using Event handling, as the screen is simply to show information and when the user has finished, they press okay and the panel should close off.
谢谢约旦
推荐答案
您可以简单地在 JOptionPane
中传递该 JPanel
的对象.例如:
You can simply pass the object of that JPanel
within the JOptionPane
. For example:
JPanel panel = new JPanel();
panel.add(new JButton("Click"));
panel.add(new JTextField(20));
panel.add(new JLabel("Label"));
JOptionPane.showMessageDialog(null,panel,"Information",JOptionPane.INFORMATION_MESSAGE);
上面的代码将把 JPanel
放在 JOptionPane
消息对话框上.当您单击 OK
时,面板将关闭.
Above code will put the JPanel
on JOptionPane
message dialog. When you click OK
the panel closes Off.
这篇关于将 JPanel 变成 JOptionPane.OK_OPTION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 JPanel 变成 JOptionPane.OK_OPTION
基础教程推荐
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 降序排序:Java Map 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01