Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: My frame wont show anything

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default My frame wont show anything

    My components dont show until I resize the frame.

    public class Frame extends JFrame{
     
    	private final static int WIDTH=400, HEIGHT=400;
     
        public Frame(){
            super();
            super.setSize(WIDTH,HEIGHT);
    		super.setVisible(true);
            super.setDefaultCloseOperation(EXIT_ON_CLOSE);
        }
     
    }

    	public class Panel extends JPanel{
     
    		private JTextField name;
     
     
     
    	    public Panel(){
    	    	super.setLayout(new BorderLayout());
    	        DrinkName = new JTextField(20);
    	        this.add(DrinkName, BorderLayout.SOUTH);
     
     
    	    }
     
    	}
    In my main class I am just creating the frame and the panel then adding the panel to the frame.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: My frame wont show anything

    Do you have a main() method for execution? Please post it.

    BTW It's best not to give your classes the same name as a Java SE class: Frame and Panel. Add a prefix like My to make them yours.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: My frame wont show anything

    Please refer to a basic Swing tutorial, like this one. There's also this index to choose from when you're ready to move to the next topic.

  4. #4
    Junior Member
    Join Date
    Mar 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My frame wont show anything

    I figured out that the problem was in my main. I rearranged the way I created the panel and frame and then put the panel in the frame. It is working now.

    One more question... Which class is recommended for button listeners? Are they allowed to go in the main?

Similar Threads

  1. Trouble getting my frame and panels to show up!?!?
    By syregnar86 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 21st, 2013, 01:12 PM
  2. New frame should only show GUI once!
    By gerre in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 30th, 2012, 10:34 PM
  3. Replies: 1
    Last Post: January 19th, 2012, 03:44 PM
  4. [SOLVED] .show is called in card layout, but the frame didn't update
    By nggdowt in forum AWT / Java Swing
    Replies: 2
    Last Post: November 9th, 2011, 02:16 AM
  5. Beginner: Show Image in Label when Results Show Up
    By Big Bundy in forum Java Theory & Questions
    Replies: 3
    Last Post: April 4th, 2011, 02:43 PM