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

Thread: Text in field objects go out of bounds..

  1. #1
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Text in field objects go out of bounds..

    I'm writing a custom notepad as a challenge for some youngsters. I need a text field so the user can write their data into. For some reason, when I try to go out of bounds or hit the button "Enter" the text will keep going, and will never create a new line.


    Here is the code. I have tried setting bounds, but it does not work.


        	private JComponent textField() {
        	    JComponent text = new JPanel();
        	    TextField field = new TextField();
        	    text.add(field);
        	    text.setLayout(new GridLayout(1, 1));
        	    return text;
        	}


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Text in field objects go out of bounds..

    First, I would not recommend combining AWT and swing...if you need a text field, use the swing equivalent JTextField. Second, a JTextField (or TextField) does not support multi-line text. If you want several lines, use a JTextArea, JTextPane, or JEditorPane.

  3. The Following User Says Thank You to copeg For This Useful Post:

    imsuperman05 (April 5th, 2012)

  4. #3
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Text in field objects go out of bounds..

    Quote Originally Posted by copeg View Post
    First, I would not recommend combining AWT and swing...if you need a text field, use the swing equivalent JTextField. Second, a JTextField (or TextField) does not support multi-line text. If you want several lines, use a JTextArea, JTextPane, or JEditorPane.
    Thank you very much, I did not know that. I just could not remember the name of the class which handled that.

Similar Threads

  1. Can't Fix Array Out of Bounds
    By Apocalypse in forum Collections and Generics
    Replies: 5
    Last Post: October 31st, 2011, 07:37 AM
  2. Replies: 3
    Last Post: April 11th, 2011, 09:51 PM
  3. Tic Tac Toe Java Application Help w/ Importing Text Field
    By Big Bundy in forum What's Wrong With My Code?
    Replies: 10
    Last Post: March 30th, 2011, 02:08 AM
  4. Replies: 3
    Last Post: February 21st, 2011, 07:25 PM
  5. Index Out Of Bounds
    By chronoz13 in forum Collections and Generics
    Replies: 1
    Last Post: December 28th, 2009, 12:19 PM