将 JPanel 变成 JOptionPane.OK_OPTION

making a JPanel into a JOptionPane.OK_OPTION(将 JPanel 变成 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

基础教程推荐