Reputation: 189646
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 with minimal other appropriate components? (e.g. just a border/closebox/etc for modeless dialog; for modal, the same + an OK/Cancel)
Upvotes: 2
Views: 4726
Reputation: 39485
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.
Upvotes: 1
Reputation: 128807
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
Upvotes: 3