Results 1 to 9 of 9
Like Tree2Likes
  • 1 Post By Junky
  • 1 Post By Junky

Thread: Problem with layout manager

  1. #1
    mDennis10 is offline Member
    Join Date
    Jul 2011
    Posts
    76
    Rep Power
    0

    Default Problem with layout manager

    I have been having this problem for quit a while which has force me to use the setBounds method. Whenever i use a layout manager sometime or most times the components are not displayed on screen. What is causing this?

    Java Code:
    	//MSMsys Constructor
    	public MSMsys ()
    	{
    		setTitle ("Management System \tMSMsys");
    		setVisible (true);
    		setSize (500,400);
    		setDefaultCloseOperation (EXIT_ON_CLOSE);
    		setLocation (300,200);
    		setLayout (new FlowLayout ());
    		
    		setMenuBar ();
    		setUserLogInPanel ();
    	}//end constructor
    	
    //Displays logInPanel with login components
    	public void setUserLogInPanel ()
    	{
    		//Create Components
    		JLabel userNameLabel = new JLabel ("User Name: ");
    		JLabel passwordLabel = new JLabel ("Password: ");
    		JPanel logInPane = new JPanel ();
    		
    		logInPane.setBorder(BorderFactory.createTitledBorder ("User Login"));
    		
    		logInPane.setLayout (null);
    		
    		//Initialize instance variables 
    		userNameTF = new JTextField (10);
    		passwordTF = new JPasswordField (10);
    		logInButt = new JButton ("Login");
    		
    		add(logInPane);
    		logInPane.add(logInButt);
    		
    		//logInPane.setBounds (50,20,280,200);
    		//logInButt.setBounds (50,20,30,30);
    		logInButt.addActionListener (new EventHandler ());
    		
    	}//logInPanel
    Last edited by mDennis10; 09-05-2011 at 02:59 AM.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Problem with layout manager

    Well obviously the answer to your problem is

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Problem with layout manager

    You're not using the layout managers correctly.

    For a more detailed answer, consider providing a more detailed question. Please see my links below for more on what we need.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Problem with layout manager

    Problem with layout manager

    Double posted with more information but still not a complete post.
    DarrylBurke likes this.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Problem with layout manager

    Quote Originally Posted by Junky View Post
    Problem with layout manager

    Double posted with more information but still not a complete post.
    We may be wasting our time here. Thanks for the heads up.
    Last edited by Fubarable; 09-05-2011 at 02:50 AM.

  6. #6
    mDennis10 is offline Member
    Join Date
    Jul 2011
    Posts
    76
    Rep Power
    0

    Default Re: Problem with layout manager

    sorry about that

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

    Default Re: Problem with layout manager

    I see that you've edited your post and now have added some code, but your code won't compile nor run for us. We don't want or need the whole program but it would be helpful for you post a small compilable runnable program that demonstrates your problem, an SSCCE. Also, read the layout manager tutorials thoroughly before using them as well as the api, and you'll see that you shouldn't be using setSize or setBounds on anything. Also, please inform us of any and all places where you've cross-posted this question. Not doing so is bad forum etiquette as we may be wasting time answering a question that has already been answered.

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Problem with layout manager

    I'm no swing expert but you might want to move the call to setVisible to be the last line.
    Fubarable likes this.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Problem with layout manager

    Quote Originally Posted by Junky View Post
    I'm no swing expert but you might want to move the call to setVisible to be the last line.
    Indeed, and call pack() before calling setVisible(true).

Similar Threads

  1. Simple GUI layout manager
    By globo in forum New To Java
    Replies: 3
    Last Post: 11-16-2010, 01:17 AM
  2. Layout Manager
    By globo in forum New To Java
    Replies: 8
    Last Post: 11-01-2010, 12:19 AM
  3. Layout manager
    By Nicholas Jordan in forum Java Applets
    Replies: 2
    Last Post: 11-24-2008, 03:02 PM
  4. Layout Manager of JApplet
    By Peter_APIIT in forum Java Applets
    Replies: 10
    Last Post: 07-19-2008, 05:37 AM
  5. MiG Layout Manager 2.4
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-16-2007, 05:11 AM

Posting Permissions

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