Results 1 to 3 of 3
  1. #1
    Janohjk is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default 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:

    Java 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.
    Last edited by Janohjk; 06-18-2011 at 03:10 AM.

  2. #2
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    4

    Default

    I have'nt use group layout, but I could say that you can use GridLayout with some panels to have
    the output that you want. Also, are you using an AWT (the Panel) on a SWING (JFrame)?

    Might be helpful
    Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)

  3. #3
    Janohjk is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default

    I solved my problem using GroupLayout in another way, thanks anyway

Similar Threads

  1. Beginner needing help
    By Krakatau7 in forum New To Java
    Replies: 15
    Last Post: 01-07-2011, 05:45 PM
  2. Ambitious Noob Here - Needing Guidance
    By DizzyEwok in forum New To Java
    Replies: 14
    Last Post: 06-28-2009, 09:25 PM
  3. All posts needing mod approval first?
    By xcallmejudasx in forum Suggestions & Feedback
    Replies: 0
    Last Post: 05-26-2009, 04:35 PM
  4. Reading Char without needing to press enter
    By x0psci in forum New To Java
    Replies: 0
    Last Post: 11-23-2007, 04:28 PM
  5. Needing Help!!
    By kingjut06 in forum JDBC
    Replies: 1
    Last Post: 07-07-2007, 11:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •