Results 1 to 4 of 4
  1. #1
    themburu is offline Member
    Join Date
    Mar 2008
    Posts
    20
    Rep Power
    0

    Post Problem here guys: Set location or setBounds

    Hi I want to build a small interactive prg but I'm having a problem with the components, I want to attain precision such that the labels match with the corresponding JTeatFields, now:
    - Must I use a Layout manager or do I Let the default take place
    - How comes if I try SetLocation or SetBound there is no effect the components just pile up and I see the last one.
    - how is it that setEchoChar('*'); gives an error

    Here's the code for my Frame1

    Java Code:
    package Frame1;
    
    import javax.swing.*;
    import java.awt.*;
    import java.io.*;
    
    public class Frame1 extends Frame{
    
    JFrame f1;
    JLabel lb1;
    JLabel lb2;
    JTextField ff1;
    JTextField ff2;
    JButton bt1;
    JButton bt2;
    
        public Frame1() {   	
        	f1 = new JFrame("Frame 1");
        	f1.setLayout(new FlowLayout());
        	f1.setSize(600, 600);
        	lb1 = new JLabel("Enter Username :");
        	lb2 = new JLabel("Enter Password :");
        	ff1 = new JTextField(25);
        	ff2 = new JTextField(25);
        	ff2.setEchoChar('*');
      
        	
        	bt1 = new JButton("OK");
        	bt1.setMnemonic('O');
        	bt2 = new JButton("Quit");
        	bt2.setMnemonic('Q');
    
       		 	
        	
        f1.add(lb1); 
    	lb1.setLocation(50, 50);
    	//lb1.setBounds(50,50,80,20);	
        f1.add(ff1);
    	ff1.setLocation(120, 50);
    	//ff1.setBounds(120,50,80,20);
        f1.add(lb2);
    	lb2.setLocation(50, 180);
    	//lb2.setBounds(50,180,80,20);
        f1.add(ff2);
    	ff2.setLocation(120, 180);
    	//ff2.setBounds(120,180,80,20);
        
        f1.add(bt1);
    	bt1.setLocation(50, 280);
    	//bt1.setBounds(50,280,80,20);
        f1.add(bt2);	
    	bt2.setLocation(120, 280);
    	//bt2.setBounds(120,280,80,20);
        
        f1.setVisible(true);	
        }
    
      
    public static void main (String[] args) {
    	new Frame1();
    }    
        
    }
    The dream of being a legend has just begun!

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    I want to attain precision such that the labels match with the corresponding JTeatFields, now:
    - Must I use a Layout manager or do I Let the default take place
    - How comes if I try SetLocation or SetBound there is no effect the components just pile up and I see the last one.
    As far as i know,

    setBounds/setLocation will only take effect if your container has no layout or null.

    But If you really need to use layout, GridBagLayout/GroupLayout may fit your needs. (Newer version of NetBeans used that)
    and you can also manage the components' behavior if its container resized.

    That's the advantage, but it takes time just to code the GUI.

    Plus,(Base of what i've observed before) it takes a little bit of time at start-up(executing the application).
    For about 600-900 milliseconds for 20 components and a container.
    freedom exists in the world of ideas

  3. #3
    themburu is offline Member
    Join Date
    Mar 2008
    Posts
    20
    Rep Power
    0

    Default How about setEchoChar

    Hi after removing the layout manger setBounds works but not etLocation however the setEchoChar still gives me errors and the component disappear after I run the application.
    The dream of being a legend has just begun!

  4. #4
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    Hi after removing the layout manger setBounds works but not setLocation
    It depends actually...

    setBounds method already covered the task of setLocation method.

    for example, by using setBounds(x,y,w,h);

    first 2 will set the x/y location of that component with respect to its container.
    second 2(w/h) will set the size of that component

    when invoking first the setBounds method before setLocation,
    setLocation takes effect. (x/y will be useless)
    if reverse invocation, setLocation will be useless.

    however the setEchoChar still gives me errors and the component disappear after I run the application.
    I would suggest not to use that kind of implementation, instead use JPasswordField.
    freedom exists in the world of ideas

Similar Threads

  1. Hi Guys
    By gibsonsydsa in forum Introductions
    Replies: 1
    Last Post: 02-06-2008, 07:36 AM
  2. Hie guys
    By heat84 in forum Introductions
    Replies: 1
    Last Post: 12-20-2007, 07:50 AM
  3. Hello guys
    By tharindu in forum Introductions
    Replies: 0
    Last Post: 11-26-2007, 08:58 AM
  4. how to get the location of some button
    By mary in forum Java 2D
    Replies: 2
    Last Post: 08-05-2007, 05:02 AM
  5. Help Me Out Guys
    By prince24 in forum New To Java
    Replies: 10
    Last Post: 07-13-2007, 05:52 PM

Posting Permissions

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