This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
[ BUILD # : Dev 20050315 ] [ JDK VERSION : 1.5.0_02 ] The defaultButton property is always disabled and cannot be set through the Form Editor property window. The defaultCapable property is enabled and can be set, but has no effect on the defaultButton property. You have to use the containing JRootPane to set this property in the source. This property should be enabled if the component is capable of being a default button in the enclosing JRootPane, and should generate code when set to a value.
JButton doesn't have a setDefaultButton(boolean method). We would have to create a special support for the requested behaviour. Changing to enhancement. See also related issue 12904.
I never said that JButton had a setDefaultButton(boolean state) method. I said that you have to use the containing JRootPane to set the default button. Like so: jButton1.getRootPane().setDefaultButton(jButton1); The fact that the DefaultButton property exists for JButtons in NetBeans, and that it does not work, is definitely a bug. However, it seems a mistake to create the property to begin with. The property does not properly present the concept that only one of a set of JButtons contained by a JRootPane can be the default button. It would probably be better to eliminate the per JButton defaultButton property, and implement a list box property for JRootPane-using components (see JRootPane JavaDoc) that lists all of the JButtons known by the Form Editor to be contained by that JRootPane and that have the defaultCapable property set to true, and allows you to choose one as the initial default button. If that makes sense, then this issue would be a defect that calls for the elimination of the per JButton defaultButton property, and issue #12904 can be updated about the eventual implementation of the list box default button property for any JRootPane-using component.
I agree that there shouldn't be a defaultButton property for JButton. I even already considered removal of this property. And now, reading your opinion, I have finally decided to remove it. So, marking this issue as fixed (according to your suggestion). Feel free to update issue 12904 with your comments. Just one note at the end - the properties of individual components are not determined by NetBeans (or at least not primarily). The form editor is based on JavaBeans specification. So, we use BeanInfos of the components to find information about their properties. For example: BeanInfo of JButton contains information about read-only property defaultButton. So, the root of the problem lies in Swing: the defaultButton is not a property of JButton, but of the JRootPane (as you correctly noted). And as such it shouldn't be mentioned by JButtonBeanInfo. There is unfortunately a lot of things like this which forces us to implement various kinds of workarounds/hacks :-( to make the GUI builder user-friendly.