Results 1 to 4 of 4

Thread: [RESOLVED] Placing objects.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Resolved [RESOLVED] Placing objects.

    ok, i'm tierd of using things such as:

    Code:
            frame.add(textArea, "North"); 
            frame.add(textField, "South");
    	frame.add(Button, "East");
    how can i place it where i want my self, instead of north, south, east or west?

    ps. i'm not using anything to design my programs, i just use plain codes.
    Last edited by Justa Lol; Nov 20th, 2008 at 06:07 PM.

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Placing objects.

    you can set the layout to null and use Component.setLocation. Or if you're using Java6 you can use the GroupLayout from the javax.swing package
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Re: Placing objects.

    i have jdk and jre6u10 if thats what you mean? but can you tell me how exactly to use those?
    Last edited by Justa Lol; Nov 20th, 2008 at 08:16 PM.

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Placing objects.

    Code:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    
    public class Test
    {
    
    	public static void main(final String[] args)
    	{
    		final JFrame frame = new JFrame("Test");
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setLayout(null);
    		final JButton btn = new JButton();
    		btn.setLocation(10, 10);
    		btn.setSize(100, 20);
    		btn.setText("I'm a button");
    		btn.addActionListener(new ActionListener()
    		{
    			@Override
    			public void actionPerformed(final ActionEvent e)
    			{
    				JOptionPane.showMessageDialog(null, "I'm a message box");
    
    			}
    		});
    		frame.add(btn);
    		frame.setSize(200, 200);
    		frame.setVisible(true);
    	}
    }
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width