Results 1 to 1 of 1
- 03-05-2010, 08:11 PM #1Member
- Join Date
- Mar 2010
- Rep Power
Overwriting add() to make an own subclass of JDialog
Maybe this question is kind of stupid but somehow I am stuck now. I've been doing all kind of GUI related work with Swing. Drawing own components is regular business. However, I wanted to create a subclass of JDialog that looks a bit nicer, however offers the same interface as the original JDialog + some more nice features. For example every of my Dialog instances will have a predefined Ok and Cancel button which are also wired with some key kisteners (Enter triggers predefined Ok-keyaction method stub, Escape another one for cancel).
One thing I also wanted to add, is a common header (like the ones you can see when creating a new class in Eclipse). Now what I did was I made JContentPane of the JDialog layed out with Borderlayout. I then added the header panel to the north, and a body panel to the centre.
Now as I mentioned before, I want to keep the same interface as the original JDialog. So if the user using my component uses MyDialogObject.add(Somecomponent), I want to pass every of those component adds to the body panel added before. I could overwrite all the add() and remove() functions but this will break the initial add of the header panel and the body panel...
Any idea how to do that in the correct way?
Also I have a second question I'm wondering how to do that. As mentioned my extended version adds some components (header, body, two buttons)... this is currently done in the constructor...
However, I want to make this class a prototype for many implementations (just like the original JDialog is a prototype components for a whole lot of specific Dialogs used in different java applications). Thus, the components header, body, buttons will have to be added to the extended prototype of my Dialog even if the user decides to implement his own constructor and overwrites the one of my superclass... So my question is: where to add the components so that the user extending my class is not able to overwrite the part which adds the initial components?
Hope I explained it clearly. If you have any questions (or even better some good advice), please post here :)
Thanks for your help already :D
- By xf021209 in forum New To JavaReplies: 12Last Post: 04-20-2009, 11:46 PM
- By John3.16 in forum AWT / SwingReplies: 7Last Post: 03-13-2009, 07:07 PM
- By Eranga in forum AWT / SwingReplies: 1Last Post: 03-28-2008, 11:26 AM
- By bugger in forum New To JavaReplies: 1Last Post: 01-13-2008, 08:31 PM
- By leonard in forum AWT / SwingReplies: 1Last Post: 08-05-2007, 05:37 AM