Results 1 to 4 of 4
  1. #1
    applewood13 is offline Member
    Join Date
    Dec 2009
    Posts
    14
    Rep Power
    0

    Cool Disable enter/return key in JTextArea

    Hello, im working on a project where i ask people to type an announcement into a textarea and it saves it to a datafile, but if you click the enter key it moves down to the next line and when it saves it to my datafile it corrupts it, so i wanted to make it so they cant click enter and start a new line. i was wondering if there is a simple way of just disabling it or if i need an keylistener and if so then how would i go about doing that?

    Thanks :(rofl):

  2. #2
    Join Date
    May 2011
    Location
    Maryland
    Posts
    38
    Rep Power
    0

    Default

    Yup, just use the setEnabled method like so..
    Java Code:
    JTextArea sample = new JTextArea();
    sample.setEditable(false);

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,192
    Rep Power
    19

    Default

    Set a DocumentFilter that doesn't pass "\n" or use the approach outlined in camickr's Single Line Text Area.

    db

  4. #4
    applewood13 is offline Member
    Join Date
    Dec 2009
    Posts
    14
    Rep Power
    0

    Default

    Thank you Darryl! that worked perfectly, exactly what i was looking for (y)

Similar Threads

  1. automatic ENTER?
    By glina126 in forum New To Java
    Replies: 3
    Last Post: 02-25-2011, 07:08 AM
  2. How Enter key act like TAB?
    By mine0926 in forum New To Java
    Replies: 2
    Last Post: 06-03-2010, 06:44 AM
  3. JTextArea on PopUp -JTextArea isn't editable
    By Richy76 in forum AWT / Swing
    Replies: 3
    Last Post: 02-01-2010, 07:51 PM
  4. Enter
    By Arnold in forum New To Java
    Replies: 8
    Last Post: 10-18-2009, 09:17 AM
  5. enter key in swt
    By ashin in forum SWT / JFace
    Replies: 0
    Last Post: 07-17-2009, 09:42 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
  •