Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Name convention on Java Swing components(prefix)

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 components.

Such as(even though other may prefer other naming conventions this is what I am currently using):

  • txt for JTextField
  • btn for JButton
  • lbl for JLabel
  • pnl for JPanel

But then my list ends..

I think such prefixes enhance the readability in my code so, but I do not have any names for components such as JComboBox, JList, JRadioButton, JCheckButton and so the list goes on.

Thanks in advance.

like image 443
LuckyLuke Avatar asked Jan 22 '11 19:01

LuckyLuke


People also ask

Which one letter is used as a prefix to swing components?

@maartinus - Following the convention that the repeating consonants are also removed, the prefix for the checkbox-type widgets should be 'chk'.

Which is the correct naming convention for Java method?

Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters.

What are the three Java naming convention?

Interface Name: Should start with uppercase letter and be an adjective e.g. Runnable, Remote, ActionListener etc. Method Name: Should start with lowercase letter and be a verb e.g. actionPerformed(), main(), print(), println() etc. Package Name: Should be in lowercase letter e.g. java, lang, sql, util etc.


1 Answers

  • btn - JButton
  • chk - JCheckBox
  • clr - JColorChooser
  • cmb - JComboBox
  • ico - JDesktopIcon
  • edt - JEditorPane
  • fch - JFileChooser
  • ifr - JInternalFrame
  • lbl - JLabel
  • lyp - JLayeredPane
  • lst - JList
  • mnu - JMenuBar
  • mni - JMenuItem
  • opt - JOptionPane
  • pnl - JPanel
  • pmn - JPopupMenu
  • prg - JProgressBar
  • rad - JRadioButton
  • rot - JRootPane
  • scb - JScollBar
  • scr - JScrollPane
  • spr - JSeparator
  • sld - JSlider
  • spn - JSpinner
  • spl - JSplitPane
  • tab - JTabbedPaneJTable
  • tbl - JTable
  • tbh - JTableHeader
  • txa - JTextArea
  • txt - JTextField
  • txp - JTextPane
  • tgl - JToggleButton
  • tlb - JToolBar
  • tlt - JToolTip
  • tre - JTree
  • vpr - JViewport

source -: http://zuskin.com/java_naming.htm

like image 51
Jamith NImantha Avatar answered Sep 23 '22 13:09

Jamith NImantha