views:

345

answers:

2

I want to implement some functionality in a library and make it available as a GUI building block for my applications. I think I would like to implement it as something that extends a JPanel, so it can be embedded as a component in other windows.

Is there a reason I should use a JDialog instead? How easy is it to create a JDialog which displays a JPanel along w/ minimal other appropriate components? (e.g. just a border/closebox/etc for modeless dialog; for modal, the same + an OK/Cancel)

+2  A: 

You should extend JDialog only if you want a Dialog, and if you want just a Panel that you can use in other Windows or Frames you should extend JPanel.

Yes, it is easy to create an JDialog just containing a JPanel with a border, closebox and OK/Cancel, both modal and not modal.

Have a look at How to Make Dialogs and How to Use Panels

Jonas
+1  A: 

I would make it a JPanel. That way you could reuse it in other components or drop it into a JFrame (by calling setContentPane) if you want to run it as a standalone. The only reason for you to need a JDialog is if you want to make your component modal.

akf