views:

82

answers:

3

Is there any naming convention for swing components such JButtons..? or does any body knows any good way for doing that?

Thanks

A: 

Hungarian naming convention, though considered bad in general, suits very well for naming Swing UI components.

Examples:
JButton for login -> bLogin, JTextField for name -> tfName etc.

missingfaktor
It's just as bad for all the same reasons.
Steve Kuo
+3  A: 

AFAIK, there is no special convention for swing elements.

The best thing you can do is using names as explicit as possible (as usual).

For my part I try to use the name of the wanted content followed by the type of the component.

For example for a textfield containing an age I would use ageTextField.
For a button used to sumbit I would use submitButton.

Colin Hebert
Isn't this makes name longer?
Feras
I prefer to have longer explicits names than shorter names with hidden senses. As long as the variable isn't named `thisIsMyFieldWhichContainsAnAgeOrMaybeABirthDayFieldText` there is no problems.
Colin Hebert
+3  A: 

You should use common sense. I prefer to add suffix to distinguish components, ie. passwordEdit, sendButton. Somebody prefers hungarian notation, but anyway, you should be consistent and use same naming conventions through all the code of your project or module.

uthark