Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 21, 2006, 08: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, 09: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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Square Reader Doesnt work with my iPhone but works with My Parents Fazzl iPhone 1 Aug 23, 2010 08:46 PM
Snow leopard antivirus works with safari, but does it work with chrome? cloakedpegasus OS X 21 May 8, 2010 04:23 PM
Javascript not working with Safari but working fine with Firefox jive Web Design and Development 5 Jul 28, 2009 09:23 AM
internet only works with wi-fi... won't work with full 3g reception! numb120 iPhone Tips, Help and Troubleshooting 3 Mar 6, 2009 11:27 AM
My Lexicon Lambda works with GarageBand but I can't get it working with LE 8 king felix Digital Audio 0 Dec 24, 2008 03:02 PM


All times are GMT -5. The time now is 11:21 AM.

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

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