He creado la siguiente clase para generar un panel con botones, el error es el siguiente:
Exception in thread "main" java.lang.IllegalStateException: javax.swing.JButton[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.5,bor der=javax.swing.plaf.BorderUIResource$CompoundBord erUIResource@3ee284,flags=296,maximumSize=,minimum Size=,preferredSize=,defaultIcon=,disabledIcon=,di sabledSelectedIcon=,margin=javax.swing.plaf.Insets UIResource[top=2,left=14,bottom=2,right=14],paintBorder=true,paintFocus=true,pressedIcon=,rol loverEnabled=true,rolloverIcon=,rolloverSelectedIc on=,selectedIcon=,text=Borrar,defaultCapable=true] is not attached to a horizontal group
at javax.swing.GroupLayout.checkComponents(Unknown Source)
at javax.swing.GroupLayout.prepare(Unknown Source)
at javax.swing.GroupLayout.preferredLayoutSize(Unknow n Source)
at java.awt.Container.preferredSize(Unknown Source)
at java.awt.Container.getPreferredSize(Unknown Source)
at javax.swing.JComponent.getPreferredSize(Unknown Source)
at java.awt.BorderLayout.layoutContainer(Unknown Source)
at java.awt.Container.layout(Unknown Source)
at java.awt.Container.doLayout(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validate(Unknown Source)
at java.awt.Window.show(Unknown Source)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at java.awt.Window.setVisible(Unknown Source)
at Principal.main(Principal.java:491)
y la clase que genera el conflicto es:
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.ParallelGroup;
import javax.swing.GroupLayout.SequentialGroup;
import javax.swing.JButton;
import javax.swing.JPanel;
public class PanelBotones extends JPanel {
PanelBotones(String nombres[], ActionListener aL){
GroupLayout fNpanelBotonesLayout = new GroupLayout(this);
ParallelGroup grupoH = fNpanelBotonesLayout.createParallelGroup(javax.swi ng.GroupLayout.Alignment.LEADING);
SequentialGroup grupoV = fNpanelBotonesLayout.createSequentialGroup();
for(int i=0;i<nombres.length;i++){
JButton boton = new JButton(nombres[i]);
boton.addActionListener(aL);
grupoH.addComponent(boton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE);
}
grupoV.addGap(19, 19, 19);
for(int x=0;x<nombres.length;x++){
JButton boton = new JButton(nombres[x]);
boton.addActionListener(aL);
grupoV.addComponent(boton);
grupoV.addPreferredGap(javax.swing.LayoutStyle.Com ponentPlacement.UNRELATED);
}
grupoV.addContainerGap(223, Short.MAX_VALUE);
fNpanelBotonesLayout.setHorizontalGroup(
fNpanelBotonesLayout.createParallelGroup(GroupLayo ut.Alignment.LEADING)
.addGroup(fNpanelBotonesLayout.createSequentialGro up()
.addContainerGap()
.addGroup(grupoH)
.addContainerGap(17, Short.MAX_VALUE)));
fNpanelBotonesLayout.setVerticalGroup(
fNpanelBotonesLayout.createParallelGroup(javax.swi ng.GroupLayout.Alignment.LEADING)
.addGroup(grupoV));
this.setLayout(fNpanelBotonesLayout);
}
}
¿Cual puede ser el problema?
Gracias