更新时间:2023-01-02 09:53:50
尝试,
JButton but = new JButton("Popup");
but.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final JPanel myPanel = new PopupPanel();// Create a separate class extends JPanel
int result = JOptionPane.showConfirmDialog(null, myPanel,
"Please Enter data into both boxes", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
}
}
});