Avatar of Reynold Nangawe
Reynold Nangawe

asked on 

How do I create a Group Layout which works

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

Java

Avatar of undefined
Last Comment
Manikandan Thiagarajan

8/22/2022 - Mon