問題描述
目前我有一個擴展 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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!