An question that was brought to my mind when programming with Swing in Java was, is it a recommendation or an \"official\"/most used naming convention(prefix) on Swing component
Why not just call JTextField textField
, JButton button
, JLabel label
, and JPanel panel
. Is it so bad to spend a few extra characters to make the variable read like an English word?
Furthermore, when I do put the type in the variable name, I put it on the end. So a JLabel that displays a name is nameLabel
(which IMO is more readable than lblName
).
And even furthermore, following duffymo's advice, it's bad practice to put the type in the variable name. A better approach is to describe what the variable is. In the case of a name label, it's a UI component that displays name. So a better name might be nameComponent
. The fact that nameComponent
is a JLabel or some other type is secondary and shouldn't clutter the variable name.