Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would suggest GroupLayout. It is more complicated to put together - you have to understand how it works. I believe this layout was designed to work with visual layout tools, but I find myself using it manually in practically every panel I build -- especially user interface panels with common form elements. It would seem perfect for a calculator application with this layout:</p> <pre> +---------------+ | Display | +---+---+---+---+ | 7 | 8 | 9 | / | +---+---+---+---+ | 4 | 5 | 6 | x | +---+---+---+---+ | 1 | 2 | 3 | - | +---+---+---+---+ | 0 | . | = | + | +---+---+---+---+ </pre> <p>Here is the constructor:</p> <pre> public CalculatorPanel() { GroupLayout layout = new GroupLayout(this); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); this.setLayout(layout); layout.setVerticalGroup(layout.createSequentialGroup() .addComponent(this.displayTextField) .addGroup(layout.createParallelGroup() .addComponent(this.sevenButton) .addComponent(this.eightButton) .addComponent(this.nineButton) .addComponent(this.divideButton)) .addGroup(layout.createParallelGroup() .addComponent(this.fourButton) .addComponent(this.fiveButton) .addComponent(this.sixButton) .addComponent(this.multiplyButton)) .addGroup(layout.createParallelGroup() .addComponent(this.oneButton) .addComponent(this.twoButton) .addComponent(this.threeButton) .addComponent(this.minusButton)) .addGroup(layout.createParallelGroup() .addComponent(this.zeroButton) .addComponent(this.decimalButton) .addComponent(this.equalsButton) .addComponent(this.plusButton))); layout.setHorizontalGroup(layout.createParallelGroup() .addComponent(this.displayTextField) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup() .addComponent(this.sevenButton) .addComponent(this.fourButton) .addComponent(this.oneButton) .addComponent(this.zeroButton)) .addGroup(layout.createParallelGroup() .addComponent(this.eightButton) .addComponent(this.fiveButton) .addComponent(this.twoButton) .addComponent(this.decimalButton)) .addGroup(layout.createParallelGroup() .addComponent(this.nineButton) .addComponent(this.sixButton) .addComponent(this.threeButton) .addComponent(this.equalsButton)) .addGroup(layout.createParallelGroup() .addComponent(this.divideButton) .addComponent(this.multiplyButton) .addComponent(this.minusButton) .addComponent(this.plusButton)))); } </pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload