For example, building a GUI in the Swing library, you often need to build a few parts within a JPanel.
eg.
public CustomPanel extends JPanel {
public CustomPanel() {
super();
// Build the slider.
{
...
}
// Build the combo boxes.
{
...
}
}
}
It seems the following are my options:
- Use the
{}
the way I am currently using them (basically for indentation of similar code). - Create custom methods for each component eg.
public JSlider createCustomSlider()
. - Create custom classes for each custom component (this seems a bit overkill if I have a number of one off components).
Is there a downside to how I indent my code with {}
?
EDIT:
Also, as an additional benefit, the braces currently serve to scope my variables. That means I'm always certain that I don't accidentally use them further down the line.