Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to put jpanel into a dialog box?

Tags:

java

swing

I need create custom dialog and put JPanel into it. Is it possible?

like image 857
joseph Avatar asked Mar 14 '10 17:03

joseph


People also ask

Can you add a JPanel to a JDialog?

You can add components to a JDialog just the way you add to a JFrame since JDialog is a java. awt. Container .

How do you add panels in JOptionPane?

You can simply pass the object of that JPanel within the JOptionPane . For example: JPanel panel = new JPanel(); panel. add(new JButton("Click")); panel.


2 Answers

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...

like image 142
ArifMustafa Avatar answered Oct 24 '22 07:10

ArifMustafa


Panel inside dialog box should have what you need.

like image 32
Anthony Forloney Avatar answered Oct 24 '22 08:10

Anthony Forloney