Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 21, 2006, 09:43 AM   #1
Uma888
macrumors 6502
 
Join Date: Jan 2005
Location: Birmingham, United Kingdom
Working with GridLayouts

Hello. Im working with layouts.

I have 5 labels, 4 buttons and a few checkboxes and a few optionboxes.

im having trouble arranging them.

im using the following code:

Code:
import javax.swing.*;
import java.awt.*;
public class ShowComponents extends JFrame
{
	public ShowComponents (String title)
	{
		super(title);
		Container contentPane = getContentPane();
				
		//create components
		JLabel label1 = new JLabel("Printer: HP Laser Jet 4000 Series PS");
		JLabel label2 = new JLabel("");
		JLabel label3 = new JLabel("");
		JCheckBox checkbox1 = new JCheckBox("Image");
		JRadioButton radiobutton1 = new JRadioButton("Selection");
		JButton button1 = new JButton("OK");
		JCheckBox checkbox2 = new JCheckBox("Text");
		JRadioButton radiobutton2 = new JRadioButton("All");
		JButton button2 = new JButton("Cancel");
		JCheckBox checkbox3 = new JCheckBox("Code");
		JRadioButton radiobutton3 = new JRadioButton("Applet");
		JButton button3 = new JButton("Setup");
	   JLabel label4 = new JLabel("");
		JLabel label5 = new JLabel("");
		JButton button4 = new JButton("Help");
		JLabel label6 = new JLabel("Print Quality");
		JComboBox combo1 = new JComboBox(new String[] {"Option 1", "Option 2"});
		JCheckBox checkbox4 = new JCheckBox("Print To File");
		//add components to the container
		contentPane.setLayout(new GridLayout(10, 10));
		contentPane.add(label1);
		contentPane.add(label2);
		contentPane.add(label3);
		contentPane.add(label4);
		contentPane.add(label5);
		contentPane.add(checkbox1);
		contentPane.add(checkbox2);
		contentPane.add(checkbox3);
		contentPane.add(checkbox4);
		contentPane.add(radiobutton1);
		contentPane.add(radiobutton2);
		contentPane.add(radiobutton3);
		contentPane.add(button1);
		contentPane.add(button2);
		contentPane.add(button3);
		contentPane.add(button4);
		contentPane.add(combo1);
		//close and exit window on click
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		pack();
		setVisible(true);
	}
	
	public static void main(String[] args)
	{
		ShowComponents frame = new ShowComponents("Show Components");
	}
}
The thing i i want them to appear in this way:



^^ CLick to see the image

Any ideas?
__________________
"If computers have no doors or fences, who needs Windows and Gates?"
Uma888 is offline   0 Reply With Quote
Old Mar 21, 2006, 10:29 AM   #2
Uma888
Thread Starter
macrumors 6502
 
Join Date: Jan 2005
Location: Birmingham, United Kingdom
Fixed it

I needed to add the components in order, i.e the order i anted em in. I had to set the grid to (3,3)
__________________
"If computers have no doors or fences, who needs Windows and Gates?"
Uma888 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
WiFi Sync Not Working iOS7, Working iOS6 kramden88 iOS 7 0 Jan 2, 2014 03:45 PM
iPhone: iPhone 5 / iPad 3 with Airport Extreme and WPA2 not working, WPA working ManuCH iOS 6 7 Aug 13, 2013 09:20 PM
Backspace & 'V' not working on keyboard passwords not working, Please help paintitblack Mac Peripherals 8 Jul 12, 2013 06:35 AM
General: The List of iOS 6 Compatible Jailbreak Tweaks (Working/Non Working) HeyGreggie Jailbreaks and iOS Hacks 363 Feb 26, 2013 07:43 PM
Why background process stops working when other programs are working? kenreaves iPhone Tips, Help and Troubleshooting 4 Aug 3, 2012 01:06 PM

Forum Jump

All times are GMT -5. The time now is 12:41 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC