Results 1 to 3 of 3
Thread: Needing help with GroupLayout
- 06-18-2011, 03:05 AM #1
Member
- Join Date
- Jun 2011
- Posts
- 2
- Rep Power
- 0
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:
The layout base was generated by netbeans, any help is welcome, thanks in advances.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); } } ); } }
Edit: This is an aproximated image of what i need.
Last edited by Janohjk; 06-18-2011 at 03:10 AM.
- 06-18-2011, 03:49 AM #2
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
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)
- 06-18-2011, 10:41 AM #3
Member
- Join Date
- Jun 2011
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Beginner needing help
By Krakatau7 in forum New To JavaReplies: 15Last Post: 01-07-2011, 05:45 PM -
Ambitious Noob Here - Needing Guidance
By DizzyEwok in forum New To JavaReplies: 14Last Post: 06-28-2009, 09:25 PM -
All posts needing mod approval first?
By xcallmejudasx in forum Suggestions & FeedbackReplies: 0Last Post: 05-26-2009, 04:35 PM -
Reading Char without needing to press enter
By x0psci in forum New To JavaReplies: 0Last Post: 11-23-2007, 04:28 PM -
Needing Help!!
By kingjut06 in forum JDBCReplies: 1Last Post: 07-07-2007, 11:38 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks