Results 1 to 5 of 5
  1. #1
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default a little Jframe problem (im doing something wrong).

    so yeah im experimenting with this way of making a JFrame, but i cant add the Jlabels annd textfields to the Jframe :/

    they labels and textfields dont show in the frame

    this is the code:
    Java Code:
    	{
    		JFrame frame = new JFrame();
    	    label6 = new JLabel("tessst");
    	    label7 = new JLabel("test");
    	    txt3 = new JTextField(10);
    	    txt4 = new JTextField(10);
    	    frame.add(label6);
    	    frame.add(label7);
    	    frame.add(txt3);
    	    frame.add(txt4);
    	    frame.setTitle("Log in ");
            frame.setSize(180, 500);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
    		}

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,334
    Rep Power
    5

    Default Re: a little Jframe problem (im doing something wrong).

    It worked. You have one big JTextField. Add this line right after creating a JFrame.

    frame.setLayout(new FlowLayout());

    Also, recommended practice is to add JPanel(s) to your JFrame and add other more specific components to the JPanel(s). This is especially true when painting.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default Re: a little Jframe problem (im doing something wrong).

    alright man, thanks.

    i knew something weird was wrong xD

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: a little Jframe problem (im doing something wrong).


  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: a little Jframe problem (im doing something wrong).

    @OP: Say if you don't understand why setting the layout resulted in all the components being visible. Or if you don't understand what the original layout was, and why the panel ended up containing a single component.

    Also, if the matter is settled, please let people know that at the other places you have started a discussion.

Similar Threads

  1. inhertiance problem what am i doing wrong?
    By monkeyjr97 in forum New To Java
    Replies: 10
    Last Post: 11-23-2012, 09:48 AM
  2. KeyPress event controlling wrong component in JFrame
    By StaticFlow in forum AWT / Swing
    Replies: 8
    Last Post: 05-22-2012, 09:29 PM
  3. Replies: 0
    Last Post: 08-30-2011, 09:18 AM
  4. JFrame and CardLayout -- Wrong Parent
    By AutoRobin in forum New To Java
    Replies: 11
    Last Post: 04-21-2011, 12:39 PM
  5. What am I doing wrong in this basic problem
    By Blaedel in forum New To Java
    Replies: 10
    Last Post: 10-11-2009, 07:45 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
  •