3

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.

This panel is triggered when the user left clicks on an ImageIcon from the main GUI and shows up on the screen.

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.

thanks Jordan

4

1 回答 1

13

您可以简单地JPanelJOptionPane. 例如:

 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面板关闭时。

于 2013-04-28T20:49:43.367 回答