Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

Edits are marked in bold:

How do I make an InputField that behaves just like the following HTML Textarea example.

<textarea rows="4" cols="50">

Specific Features that are ideal:

  1. Text box has fixed height with scrollbar (The scrollbar must shrink to content size)
  2. Ctrl+a selects all content
  3. Enter key works correctly (The InputField auto scrolls to bottom as user inserts new line)
  4. The text wrapping works appropriately

I looked through the docs unable to find an example that follows those specifications.

This question is quiet close, but I can't seem to keep the content autoscrolled when the user enters a new line and the text wrapping isn't working correctly.

share|improve this question

marked as duplicate by Leonid Shifrin, halirutan, Artes, Yves Klett, m_goldberg Jun 15 '13 at 17:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

concerning the Enter key see : – andre Jun 15 '13 at 8:08
On my system (OS X), I can start a new line in your input field by entering Ctrl-J. – m_goldberg Jun 15 '13 at 8:23
@LeonidShifrin The linked question works quiet wells except it doesn't have scrollbar support that I am aware of. Are you aware of way to possible fix this? – Liam Jun 15 '13 at 16:49
@LeonidShifrin I have modified it to support the scrollbar, but I have amended the specifications slightly. Ideally the scrollbar should autoscroll to the bottom when a user enters a new line. – Liam Jun 15 '13 at 17:10
@Liam I have been thinking about it, for my own purposes, but did not implement yet. Similar scrolling issues have been discussed before here and in the question of which that one is a duplicate. – Leonid Shifrin Jun 15 '13 at 19:03
up vote 5 down vote accepted

Perhaps this slightly modified version of your code is closer to what you want. Remember, Ctrl+J, not Enter, to start a new line.

DynamicModule[{data = "some\ndata"}, 
      Pane[InputField[Dynamic@data, String, 
        ContinuousAction -> True,
        Appearance -> None, 
        FieldSize -> {Automatic, {1, Infinity}}], 
        ImageSize -> {300, 100}, 
        ImageMargins -> 0, 
        AppearanceElements -> {},
        FrameMargins -> {{5, 5}, {0, 0}},
        Scrollbars -> {False, True}],
        Background -> White,
        FrameMargins -> 0,
        FrameStyle -> Gray],

enter image description here

share|improve this answer
Crtl+J does not work for me (Win7), but it showed me how to add tags to current cell what I find useful. :) – Kuba Jun 15 '13 at 10:07
@Kuba. Perhaps someone using Window can tell us what keystroke will work there. – m_goldberg Jun 15 '13 at 10:48
I have noticed that if you type in text until the end of the line, that it wraps quiet funny. The text doesn't doesn't appear to fill up the first line before going onto the next. Additionally I noticed if I start pressing the space bar the text wraps a lot sooner then where the scrollbar is. After some trail and error it seems FieldSize -> {30, {1, Infinity}}],FrameMargins -> {{0, 0}, {0, 0}} seems to fix the 2nd issue, but I'm not so sure about the text wrapping issue. – Liam Jun 15 '13 at 16:28
@Kuba I have edited the code to use EventHandler to get around the Enter key issue. I am not going to make this answer correct yet to see if someone comes up with a better answer(well shorter), more importantly the text is wrapping is wrong making the editor quiet difficult is use. – Liam Jun 15 '13 at 16:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.