I need create custom dialog and put JPanel into it. Is it possible?
You can add components to a JDialog just the way you add to a JFrame since JDialog is a java. awt. Container .
You can simply pass the object of that JPanel within the JOptionPane . For example: JPanel panel = new JPanel(); panel. add(new JButton("Click")); panel.
Probably you need this,
JPanel myPanel = new JPanel();
myPanel.setBounds(0, 0, 400, 450);
myPanel.setBackground(Color.YELLOW);
JOptionPane jop = new JOptionPane();
JDialog dialog = jop.createDialog("This is my Dialog");
dialog.setSize(400, 450);
dialog.setContentPane(myPanel);
dialog.setVisible(true);
I have tested this code, and working fine for me...
Panel inside dialog box should have what you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With