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 7 of 7

Thread: TextField taking up the entire window space

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default TextField taking up the entire window space

    I have created a TextField in a frame but it takes up the entire window space. Below is the code

    TextField licenseID = new TextField("My Text box");
    licenseID.setBackground(Color.blue);
    licenseID.setSize(20, 20);
    add(licenseID);

    This code is written inside the class -
    class EnterLicense extends Frame

    I am setting the size to 20,20 but it takes up the entire window size. Can someone please help?


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,609
    Thanks
    25
    Thanked 316 Times in 295 Posts

    Default Re: TextField taking up the entire window space

    Are you adding to the frame or a JPanel? I believe this is an issue with the default layout manager or something. I can't remember off the top of my head since I haven't done any low-level GUI work for years. You either need to call getContentPane().add(licenseID);, or you need to create a new JPanel, add licenseID to the new JPanel, and then add the new JPanel to your frame.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Junior Member
    Join Date
    May 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: TextField taking up the entire window space

    I am adding this to Frame (i cannot use JPanel). I tried using getContentPane() but it says getContentPane() is undefined.

  4. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,609
    Thanks
    25
    Thanked 316 Times in 295 Posts

    Default Re: TextField taking up the entire window space

    Why can't you use JPanels? The assignment specifics or something? Can you use any sort of container? Is it a Frame or a JFrame?
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  5. #5
    Junior Member
    Join Date
    May 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: TextField taking up the entire window space

    It is Frame. What kind of container can I use to fix this?

  6. #6
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,609
    Thanks
    25
    Thanked 316 Times in 295 Posts

    Default Re: TextField taking up the entire window space

    Well, since Frame is a Container, then you may be able to just change the LayoutManager. Try saying:
    frame.setLayout(new FlowLayout());
    before you add anything.
    No idea if it will work, but its worth a try.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  7. #7
    Junior Member
    Join Date
    May 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: TextField taking up the entire window space

    Million thanks!!! It worked

Similar Threads

  1. Replies: 1
    Last Post: December 17th, 2011, 02:32 AM
  2. WHY AM I HAVING TO PUT THE ENTIRE FILE PATH?!?!
    By CameronHussey in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 7th, 2011, 05:32 AM
  3. Reading in entire contents of text file to one string
    By fortune2k in forum File I/O & Other I/O Streams
    Replies: 9
    Last Post: December 12th, 2010, 06:03 PM
  4. Taking an element out of an array
    By SlckP in forum Collections and Generics
    Replies: 3
    Last Post: May 5th, 2010, 02:26 PM