Results 1 to 8 of 8
  1. #1
    danpotter is offline Member
    Join Date
    May 2011
    Posts
    43
    Rep Power
    0

    Default Layout Vs Setbounds or setlocation problem..

    well..in frames or JFrames..,,we all use setbounds and setlocation to place the components in required place in frame or JFrame,but if we resize the frame,we can observe the contents get hide...,so we use a Layout inorder to make all contents visible even after resizing..,but in Layout all placing of contents is default and we cant able to make changes using setbounds or setlocation and make to place the contents in our required position in frame or JFrame..

    BECAUSE OF THIS SIMPLE ISSUE,MY MINI PROJECT GOT STOPPED IN THE MIDDLE..


    so what exactly we can do if we want to place components in our required positions even by using Layout???

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,040
    Rep Power
    10

    Default Re: Layout Vs Setbounds or setlocation problem..

    Why do you think you need to absolutely position your components?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    danpotter is offline Member
    Join Date
    May 2011
    Posts
    43
    Rep Power
    0

    Default Re: Layout Vs Setbounds or setlocation problem..

    well..just for some purposes..like...we want to places components in various parts of the frame,...as per the suggestions given to us by our project mentor...then what we need to do??

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,040
    Rep Power
    10

    Default Re: Layout Vs Setbounds or setlocation problem..

    I highly recommend you use a layout manager. Note that you can nest layouts by putting a JPanel with one layout inside another JPanel with a different layout. A quick google of "java layout manager tutorial" will give you a link to Sun's (Oracle's) tutorial, which should be your first source of information.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    danpotter is offline Member
    Join Date
    May 2011
    Posts
    43
    Rep Power
    0

    Default Re: Layout Vs Setbounds or setlocation problem..

    well...im directly entering into the point..,here is my code....

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class lms extends JFrame implements ActionListener{
    
    	static JFrame frm;
    	JPanel pan;
    	JTextField name,pswd;
    	JLabel lbl1,lbl2,lbl3,lbl4,lbl5;
    	JButton b1;
    
    	GridLayout g;
    	public lms(){
    
    frm=new JFrame("LMS");
    pan=new JPanel();
    
    
    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frm.getContentPane().add(pan);
    pan.setLayout(new GridLayout(4,3,20,50));
    
    	lbl1=new JLabel("Name : ");
    	lbl2=new JLabel("Password : ");
    	lbl3=new JLabel("Welcome To LMS");
    lbl4=new JLabel();
    
    
    		name=new JTextField(2);
    		pswd=new JTextField(2);
    		//pswd.setEchoChar('*');
    		b1=new JButton("OK");
    		name.setBackground(Color.pink);
    		name.setForeground(Color.blue);
    		Font f=new Font("Arial",Font.BOLD,15);
    		Font z=new Font("Arial",Font.ITALIC+Font.BOLD,15);
    
    		name.setFont(f);
    		lbl1.setFont(f);
    		lbl2.setFont(f);
    		lbl3.setFont(z);
    		lbl4.setFont(f);
    		lbl4.setForeground(Color.RED);
    
    
    		
    		pswd.setFont(f);
    		b1.setFont(f);
    		
    		lbl1.setBounds(50,200,20,20);
    		lbl2.setBounds(50,250,20,20);
    		lbl3.setBounds(50,80,20,20);
    		lbl4.setBounds(100,350,20,20);
    		
    		name.setBounds(80,100,20,25);
    		pswd.setBounds(80,100,20,25);
    
    	
    		b1.setFont(f);
    		
    		b1.setBounds(200,300,50,30);
    		
    	
    		b1.addActionListener(this);
    		
    		pan.add(lbl3);
    		pan.add(lbl1);
    		pan.add(name);
    		pan.add(lbl2);
    		pan.add(pswd);
    		pan.add(b1);
    		pan.add(lbl4);
    		
    	
    		addWindowListener(new WindowAdapter(){
    			public void windowClosing(WindowEvent e){
    				System.exit(0);
    			}
    		});	
    	
    	}
    
    	public void actionPerformed(ActionEvent ae){
         
                    String s1=name.getText();
    			String s2=pswd.getText();
    				
    if(ae.getSource()==b1 && s1.isEmpty() && s2.isEmpty())
    {
    lbl4.setText("Please Enter Username and Password!!!");
    
    }
    
    else if(s1.equals(s2)){
    			GetFrame2 f2=new GetFrame2();
    			f2.setSize(500,500);
    			f2.setVisible(true);
    			setVisible(false);}
    else
    {
    lbl4.setText("Enter Correct Username and password!!!");
    }
    		
    }
    	public static void main(String args[]){
    lms l1=new lms();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    frm.setSize(screenSize.width, screenSize.height);
    frm.setVisible(true);
    	}
    }
    NOW I WANT A LOGIN PAGE WHERE heading "WELCOME TO LMS" SHOULD BE ON TOP CENTER AND USERNAME AND BELOW IT PASSWORD AND BELOW IT OK BUTTON..SO WHAT CHANGES I NEED TO DO IN
    pan.setLayout(new GridLayout(4,3,20,50));
    PLEASE TELL ME...

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Layout Vs Setbounds or setlocation problem..

    Do you have a problem with your Shift and/or Caps Lock key?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Layout Vs Setbounds or setlocation problem..

    Quote Originally Posted by danpotter View Post
    well...im directly entering into the point..,here is my code....
    NOW I WANT A LOGIN PAGE WHERE heading "WELCOME TO LMS" SHOULD BE ON TOP CENTER AND USERNAME AND BELOW IT PASSWORD AND BELOW IT OK BUTTON..SO WHAT CHANGES I NEED TO DO IN PLEASE TELL ME...
    Please don't shout, we can read you much better if you avoid all-caps. As for changes, I recommend you have a look at the layout tutorial as it will give pictorial examples of the different layouts, and then that you use this information to experiment and try out different combinations of layouts. Working this way, you'll likely both find a good combination of layouts and gain a much better understanding of the different layout managers than you would if we told you to do "this, this, and this". Also, if you do this, and get stuck, come back with your latest code and any *specific* questions, and we'll be glad to try to help you out.

  8. #8
    danpotter is offline Member
    Join Date
    May 2011
    Posts
    43
    Rep Power
    0

    Default Re: Layout Vs Setbounds or setlocation problem..

    hey guyzz...dont take it[using caps] in wrong way,...its all because of some problem in my Keyboard..LOL..now i got my new keyboard...anyways...thnx for ur suggestion..surely i will do what u said... :D

Similar Threads

  1. Replies: 1
    Last Post: 03-18-2012, 01:00 PM
  2. GUI Problem with setBounds();
    By JohnPringle83 in forum New To Java
    Replies: 2
    Last Post: 05-17-2011, 08:18 AM
  3. control setLocation setBounds
    By xna in forum New To Java
    Replies: 3
    Last Post: 11-11-2009, 05:29 AM
  4. setLocation on a JDialog is ignored
    By ScottVal in forum AWT / Swing
    Replies: 7
    Last Post: 01-13-2009, 08:35 AM
  5. Problem here guys: Set location or setBounds
    By themburu in forum New To Java
    Replies: 3
    Last Post: 06-03-2008, 08:19 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
  •