Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First of all: You can use arrays for your text fields:</p> <pre><code>JTextField[][] matrix1TextFields, matrix2TextFields, matrix3TextFields; private void refreshMatrixComponents(int r, int c) { matrix1TextFields = new JTextField[r][c]; matrix2TextFields = new JTextField[r][c]; matrix3TextFields = new JTextField[r][c]; for (int row = 0; row &lt; r; row++) { for (int col = 0; col &lt; c; col++) { matrix1TextFields[row][col] = new JTextField(); matrix2TextFields[row][col] = new JTextField(); matrix3TextFields[row][col] = new JTextField(); } } placeMatrixTextField(); } </code></pre> <p>For the layout manager, there are a lot of options. I would either recommend <code>GridLayout</code> (very easy to use) or <code>GridBagLayout</code> (more difficult to use, but more flexible) or something 3rd party like <code>MigLayout</code> (you will have to dive into the syntax a bit, but I think it's totally worth the effort). I also recommend creating a <code>JPanel</code> for every matrix and put all the text fields in there. Then place those <code>JPanels</code> + the rest of the components:</p> <pre><code>JPanel matrix1Panel, matrix2Panel, matrix3Panel; private void placeMatrixTextField() { int r = matrix1TextFields.length, c = matrixTextFields[0].length; matrix1Panel = new JPanel(); matrix2Panel = new JPanel(); matrix3Panel = new JPanel(); matrix1Panel.setLayout(new GridLayout(r, c)); matrix2Panel.setLayout(new GridLayout(r, c)); matrix3Panel.setLayout(new GridLayout(r, c)); for (int row = 0; row &lt; r; row++) { for (int col = 0; col &lt; c; col++) { matrix1Panel.add(matrix1TextFields[row][col]); matrix2Panel.add(matrix2TextFields[row][col]); matrix3Panel.add(matrix3TextFields[row][col]); } } // now place your panels } </code></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