Needing help with GroupLayout
Im trying to add items to a GroupLayout, those items are generated by another class, the items are added by a for, but currently it is adding one group or the old ones are replaced by the newer, im not sure, this is my code:
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class myClass extends JFrame
{
private static final int NUMERO_PANELES = 2;
Panel[] paneles = new Panel[NUMERO_PANELES];
public myClass()
{
super("MyTest");
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
for(int i = 0; i < NUMERO_PANELES; i++)
{
Panel aux = new Panel();
aux.build(); // here we build the buttons and other components
paneles[i] = aux;
}
GroupLayout.Group horizontal = layout.createParallelGroup(GroupLayout.Alignment.LEADING);
for(int i = 0; i < NUMERO_PANELES; i++)
{
Panel temporal = paneles[i];
GroupLayout.Group temporalGroup = layout.createSequentialGroup()
.addContainerGap()
.addComponent(temporal.getBotonDo(), GroupLayout.PREFERRED_SIZE, 54, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(temporal.getBotonRe(), GroupLayout.PREFERRED_SIZE, 54, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(temporal.getBotonMi(), GroupLayout.PREFERRED_SIZE, 54, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(temporal.getBotonFa(), GroupLayout.PREFERRED_SIZE, 54, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(temporal.getBotonSol(), GroupLayout.PREFERRED_SIZE, 54, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(temporal.getBotonLa(), GroupLayout.PREFERRED_SIZE, 54, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(temporal.getBotonSi(), GroupLayout.PREFERRED_SIZE, 54, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(temporal.getBotonDoAlto(), GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
.addComponent(temporal.getTempo()).addComponent(temporal.getInstrumentos(), 0, 95, Short.MAX_VALUE))
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(temporal.getBotonSet(), GroupLayout.PREFERRED_SIZE, 54, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(temporal.getBotonPlay(), GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE);
horizontal.addGroup(temporalGroup);
}
layout.setHorizontalGroup(horizontal);
GroupLayout.Group vertical = layout.createParallelGroup(GroupLayout.Alignment.LEADING);
for(int i = 0; i < NUMERO_PANELES; i++)
{
Panel temporal = paneles[i];
GroupLayout.Group temporalGroup = layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
.addComponent(temporal.getBotonDoAlto(), GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
.addGroup(GroupLayout.Alignment.LEADING, layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(temporal.getBotonSet(), GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
.addComponent(temporal.getBotonPlay(), GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE))
.addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(temporal.getInstrumentos(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
.addComponent(temporal.getTempo(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addComponent(temporal.getBotonDo(), GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
.addComponent(temporal.getBotonRe(), GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
.addComponent(temporal.getBotonMi(), GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
.addComponent(temporal.getBotonFa(), GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
.addComponent(temporal.getBotonSol(), GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
.addComponent(temporal.getBotonLa(), GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
.addComponent(temporal.getBotonSi(), GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE))
.addContainerGap();
vertical.addGroup(temporalGroup);
}
layout.setVerticalGroup(vertical);
pack();
}
public static void main(String[] params)
{
java.awt.EventQueue.invokeLater(
new Runnable()
{
public void run()
{
new myClass().setVisible(true);
}
}
);
}
}
The layout base was generated by netbeans, any help is welcome, thanks in advances.
Edit: This is an aproximated image of what i need.
http://imagesi.com/1780f.bmp