Skip to content
Advertisement

How does java dialog inheritance work? I lose some properties

Sorry I don’t have much knowledge about Java or swing applications. I created a dialog called DlgShape and in it i have 2 text fields, 2 buttons and 2 labels. I tried creating DlgRectangle and instead of it inheriting from JDialog I inherited from DlgShape. The design of the parent and child class are identical but in the DlgRectangle I don’t have the labels, buttons and text fields listed out as properties, I have public get and set methods and getContentPane. Suddenly my layout of the DlgRectangle changed from GridBagLayout to BorderLayout, why did it do that? I have the default DlgShape constructor set the layout to GridBagLayout and my DlgRectangle constructor also calls the super constructor.

I tried manually typing the code to create a label and put it in the content panel but it doesn’t appear. I had a thought that maybe I need to get the content panel to be a property of DlgShape and maybe make it protected.

Here’s my code for DlgShape: package drawing;

JavaScript

and code for DlgRectangle, well DlgRectangle1 but lets call it DlgRectangle:

JavaScript

Advertisement

Answer

I just needed to switch my properties in DlgShape from private to public or protected.

So

JavaScript

should be

JavaScript

Credits go to the comment by @Bohemian

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement