Layout Managers: GridBagLayout
32
private final int CENT = GridBagConstraints.CENTER;
private final int WEST = GridBagConstraints.WEST;
private final int SOEA = GridBagConstraints.SOUTHEAST;
private final int HORI = GridBagConstraints.HORIZONTAL;
private final int RELA = GridBagConstraints.RELATIVE;
private final int REMA = GridBagConstraints.REMAINDER;
final int[][] gMain = new int[][] {
{0, 0}, {RELA, 5 }, {BOTH, CENT}, {4, 2, 4, 2},
{1, 0}, {REMA, 1 }, {HORI, CENT}, {4, 2, 2, 4},
{0, 6}, {RELA, REMA}, {HORI, SOUT}, {2, 4, 4, 2},
{1, 1}, {REMA, 1 }, {HORI, CENT}, {2, 2, 2, 4},
{1, 2}, {REMA, 1 }, {HORI, CENT}, {2, 2, 2, 4},
{1, 3}, {REMA, 1 }, {NONE, CENT}, {2, 2, 2, 4},
{1, 4}, {REMA, 1 }, {NONE, CENT}, {2, 2, 2, 4},
{1, 5}, {REMA, 1 }, {NONE, CENT}, {2, 2, 2, 4},
{1, 6}, {REMA, RELA}, {HORI, CENT}, {2, 2, 2, 4},
{1, 7}, {REMA, REMA}, {HORI, CENT}, {2, 2, 4, 4}
};
final double[][] wMain = new double[][] {
{1.0, 0.8},
{0.0, 0.1},
{1.0, 0.2},
{0.0, 0.1},
{0.0, 0.1},
{0.0, 0.1},
{0.0, 0.1},
{0.0, 0.1},
{0.0, 0.1},
{0.0, 0.1}
};
}
Como veis la clase consta de dos arrays, uno de enteros y otro de números decimales que
especifican los valores de las restricciones para cada uno de los componentes del interfaz
gráfico. Cada línea representa a un componente del interfaz. Habrá tantos componentes como
líneas de restricción tengamos. El significado de las líneas es el siguiente:
•línea de enteros: {#, #}, {#, #}, {#, #}, {#,#,#,#}
{gridx, gridy}, {gridwidth, gridheight}, {fill, anchor}, {top, bottom,left right}(insets)
•línea de decimales: {#,#}
{weightx, weighty}