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
基础教程推荐
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
