Salve a tutti, non riesco a inserire un JPane settato con GridBagLayout dentro un altro settato allo stesso modo!!!
// bottone di aggiunta
JButton add = new JButton(" Add ");
// pan
areaBox = new JPanel( new GridBagLayout() );
areaBox.setVisible(true);
// GridBagLayout
final GridBagConstraints gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 0;
gc.anchor = GridBagConstraints.WEST;
panel = new JPanel( new GridBagLayout() );
gc.gridx = 0;
gc.gridy = 0;
gc.fill = GridBagConstraints.NONE;
panel.add(add, gc);
gc.gridx = 0;
gc.gridy = 1;
gc.fill = GridBagConstraints.NONE;
panel.add(areaBox, gc);
add.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent addEvent){
try{
// aggiunta dell'ultimo job
panel.add( nuovoPanSettatoConGridBagLayout, gc); // <------ Aggiunta panel settato con GridBagLayout
areaBox.repaint();
getContentPane().revalidate();
getContentPane().repaint();
pack(); // <------ errore ???
}
catch ( Exception err ){
err.printStackTrace();
}
}
});
pack();
Ho questo errore
java.lang.IllegalArgumentException: illegal anchor value
at java.awt.GridBagLayout.AdjustForGravity(GridBagLayout.java:1763)
....