code_junkie

Which Layout Manager do you use?

Nov 11th, 2011
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. private void layoutComponents(){
  2. JPanel panel = new JPanel();
  3.  
  4. GroupLayout layout = new GroupLayout(panel);
  5. panel.setLayout(layout);
  6.  
  7. layout.setAutoCreateGaps(true);
  8.  
  9. layout.setAutoCreateContainerGaps(true);
  10. SequentialGroup hGroup = layout.createSequentialGroup();
  11.  
  12. JLabel nameLbl = new JLabel("Name");
  13. JLabel countLbl = new JLabel("Amount");
  14. JLabel dateLbl = new JLabel("Date(dd/MM/yy)");
  15. hGroup.addGroup(layout.createParallelGroup().
  16. addComponent(nameLbl).
  17. addComponent(countLbl).
  18. addComponent(dateLbl).
  19. addComponent(go));
  20.  
  21. hGroup.addGroup(layout.createParallelGroup().
  22. addComponent(name).
  23. addComponent(count).
  24. addComponent(date));
  25.  
  26. layout.setHorizontalGroup(hGroup);
  27.  
  28. SequentialGroup vGroup = layout.createSequentialGroup();
  29.  
  30. vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).
  31. addComponent(nameLbl).addComponent(name));
  32. vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).
  33. addComponent(countLbl).addComponent(count));
  34. vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).
  35. addComponent(dateLbl).addComponent(date));
  36. vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).
  37. addComponent(go));
  38. layout.setVerticalGroup(vGroup);
  39.  
  40. frame.add( panel , BorderLayout.NORTH );
  41. frame.add( new JScrollPane( textArea ) );
  42. }
  43.  
  44. DesignGridLayouut layout = new DesignGridLayout(myPanel);
  45. layout.row().grid(lblFirstName).add(txfFirstName).grid(lblSurName).add(txfSurName);
  46. layout.row().grid(lblAddress).add(txfAddress);
  47. layout.row().center().add(btnOK, btnCancel);
  48.  
  49. PainlessGridBag gbl = new PainlessGridBag(getContentPane(), false);
  50.  
  51. gbl.row().cell(lblFirstName).cell(txtFirstName).fillX()
  52. .cell(lblFamilyName).cell(txtFamilyName).fillX();
  53. gbl.row().cell(lblAddress).cellXRemainder(txtAddress).fillX();
  54.  
  55. gbl.doneAndPushEverythingToTop();
Add Comment
Please, Sign In to add comment