views:

735

answers:

4

The team in which I work has been getting problems with the visual inheritance of the forms in the Java platform.

We want to develop a base JFrame with some controls in it and to have inherited forms from that base JFrame. The designer of the Netbeans 6.1 does not paint the controls of the base form in the inherited ones, so we can´t use it in the way we want. In the execution time the inherited forms are well painted, with the parent´s controls.

The Netbeans designer

Anyone has solved it? Should we change of IDE?

+1  A: 

Just a general comment, not a real answer to your situation - visual components aren't made for inheritance. For example, see the horrible blunder Sun made by inheriting everything from Component- now you have a JList which you can't use .add() on to add items to. Unless you can fulfill the entire super-class contract (and I know only of several classes that can) prefer composition rather than inheritance. Expose the methods you do plan on fulfilling and a "Component getAsComponent()" method with the explicit declaration that the component shouldn't be changed directly. I find that much easier than having to think about "what should I do if someone uses add(JLabel) to my component? or setLayout()?".

Regarding your specific predicament - I'm using JFormDesigner in IntelliJ IDEA but it might apply as well. JFD has a nice way of using the component BeanInfo information (for component named "MyThingy" the info class would be "MyThingyBeanInfo"). Using that class you can define a lot of things for design-time only consumption, along with special painting methods and other niceties.

Ran Biron
+1  A: 

AFAIK, Matisse is not really designed to create inhereted forms. It is designed for composition (i.e. create a custom JComponent and drop it into your Matisse Form).

The form designer does not use the java file to create the form, it uses the "form" file. This does not get inhereted. If you absolutely need to use inheritance (which I would recommend against), then you will need to copy the contents of the "form" file into your child class.

Generally, you should create a custom JPanel of some sort (using Matisse or not) and then drop this form into your JFrame. Any custom code/events that needs to be reused should be attached to the JFrame should be created in beans and then added to the form.

Netbeans 7 is looking at revamping the code-generation of Matisse. I'd suggest putting this in as an enhancement request at www.netbeans.org.

James Schek
A: 

Hi, I have tried this on netbeans 6.7 but I can't see the controls defined on the base Jframe on the sub window class at design time. any idea?

A: 

Jaguard, you must change the access var control (right-click on control, select 'customize code', see the botton of the window)

valmir