We help IT Professionals succeed at work.

How do I create a Group Layout which works

Reynold Nangawe
on
66 Views
Last Modified: 2017-04-18
I have created a group layout as defined bellow but it doesn't work, I try to add groups to bigger groups, what am I doing wrong? Can anyone help?

search = new JTextField();
				srch = new JButton ("Search");
				
				JLabel disptitle = new JLabel("");
				BufferedImage buttonIcon = ImageIO.read(new File("Graphics/back.jpg"));
				BufferedImage buttonIcon2 = ImageIO.read(new File("Graphics/home.jpg"));
				BufferedImage buttonIcon3 = ImageIO.read(new File("Graphics/forward.jpg"));
				
				bck = new JButton (new ImageIcon(buttonIcon));
				frw = new JButton (new ImageIcon(buttonIcon3));
				hme = new JButton (new ImageIcon(buttonIcon2));
				
				JTextArea textArea = new JTextArea (16, 58);
				textArea.setSize(400,400);
				JScrollPane scroll = new JScrollPane (textArea,
				JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
				System.out.println ("Test b");
				JTextArea textArea2 = new JTextArea (16, 58);
				textArea.setSize(400,400);
				JScrollPane scroll2 = new JScrollPane (textArea2,
				JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
				
				GroupLayout.SequentialGroup navigation = layout.createSequentialGroup();
				navigation.addComponent(bck);
  		  		navigation.addComponent(frw);
				navigation.addComponent(hme);
				
				GroupLayout.SequentialGroup searche = layout.createSequentialGroup();
				searche.addComponent(search);
  		  		searche.addComponent(srch);
				
				GroupLayout.SequentialGroup naviga = layout.createSequentialGroup();
				naviga.addComponent(disptitle);
  		  		naviga.addGroup(navigation);
				
				GroupLayout.SequentialGroup leftToRight = layout.createSequentialGroup();
  		  		leftToRight.addGroup(searche);
  		  		leftToRight.addGroup(naviga);
				
  				GroupLayout.SequentialGroup topToBottom = layout.createSequentialGroup();
    			GroupLayout.ParallelGroup rowTop = layout.createParallelGroup();
    			rowTop.addGroup(searche);
				rowTop.addGroup(naviga);
    			topToBottom.addGroup(rowTop);
    		System.out.println ("Test c");	
				GroupLayout.SequentialGroup iga = layout.createSequentialGroup();
				iga.addComponent(scroll);
				GroupLayout.SequentialGroup igade = layout.createSequentialGroup();
				igade.addComponent(scroll2);
				
				
				GroupLayout.ParallelGroup rowBot = layout.createParallelGroup();
    			rowBot.addGroup(iga);
    			rowBot.addGroup(igade);
    			topToBottom.addGroup(rowBot);
	
  			  	layout.setHorizontalGroup(navigation);
  		 	 	layout.setHorizontalGroup(searche);
  		 	 	layout.setHorizontalGroup(naviga);
				layout.setHorizontalGroup(leftToRight);	
				layout.setHorizontalGroup(topToBottom);
  		 	 	
				window.add(panel);
				System.out.println ("Test A");
				window.pack();
    			window.setVisible(true);
			

Open in new window

Comment
Watch Question

Senior consultant
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Manikandan ThiagarajanSenior consultant

Commented:
close

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.