Results 1 to 7 of 7
  1. #1
    angues is offline Member
    Join Date
    Jan 2009
    Posts
    4
    Rep Power
    0

    Default Insert text at abitrary point in a JTextPane

    Hi,

    This is my first post on this forum though I have read it many times to solve problems I've been having, so thanks everyone :)

    I have a question regarding the JTextPane, and if it's possible to insert text at any point in it? i.e. to be able to 'click-and-type' as with something like Word, and then start writing at that point regardless of whether there is text before or not.

    I looked around for a long time to try and find an answer for this but so far have not had any luck. I thought it would be a case of moving the caret to the new position but the caret can't be moved past the text already in the pane. I want to for example be able to create a new pane and start typing in the middle. Is this possible?

    I've managed to accomplish this so far by flooding the pane with spaces when I create it, but it seems to be a bit of a hack and I'm sure there must be a better way!

    Any help would be really appreciated :)

    Thanks

  2. #2
    angues is offline Member
    Join Date
    Jan 2009
    Posts
    4
    Rep Power
    0

    Default

    Anyone have any ideas?

  3. #3
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

    Default

    No, you can't do that. You can't do that in M$ Word, either.

    You want to do something like a graphics program, where you can draw anywhere in the canvas.

  4. #4
    angues is offline Member
    Join Date
    Jan 2009
    Posts
    4
    Rep Power
    0

    Default

    Hi,

    Thanks for your reply, though regarding Word you can do this and I have been doing it for a number or years now. It's called 'Click and Type' (can't post a link as my post count isn't 20 yet, but a click search for 'Word click and type' on google brings up pages on it)

    However I've just been playing around with Word now with the paragraph marks enabled and it appears to just insert the new lines up to the point where you want to type, and then I guess some spaces? But it does have the effect that you can double click and start typing anywhere within the document.

    As I said I've been able to acheive this so far by filling the text pane with spaces before its displayed to the user, but was wondering if there is a better way? Perhaps there isn't, but it seems a bit wrong to workaround the problem like this?

  5. #5
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

    Default

    When I mentioned Word, I meant its normal functions, not creating a text box. JTextPane certainly does not have that function.

    Again, you trying take a text-based component and turn it into a graphics component.

    You can look at Java graphics in the tutorial. Note that this will not yield a purely text-based solution...

  6. #6
    angues is offline Member
    Join Date
    Jan 2009
    Posts
    4
    Rep Power
    0

    Default

    Hi,

    When I mentioned Word I also meant its normal functions, I made no mention of using text boxes...If you open a new document and double click anywhere in the document you can type at that point, Word will figure out the formatting required to let you do this on the fly. This is an alternative to having to enter several line returns as soon as you open the document to get to the right location.

    Also as I said I have managed to accomplish this by filling the text pane with spaces when it is initialised, which means there is 'text' everywhere and you can then obviously click and type over the text at any location (so in effect giving the illusion of being able to type anywhere), but was wondering if there is a better way to do this as this seems a bit clunky.

    It's not graphics that I'm after, its pure text as I have said, hence the reason for using a JTextPane :) The text pane should support cut/copy/paste etc as normal for a text component, just with the added feature of not having to start typing in the upper left corner but rather being able to begin typing anywhere.

    Any suggestions on a 'nicer' way than filling the pane with spaces before hand would be great, but if not what I have now works, it just seems a bit 'wrong' from a design point of view :P

    Thanks

  7. #7
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

Similar Threads

  1. Help! - How to insert a new line to a text file
    By matpj in forum New To Java
    Replies: 13
    Last Post: 02-24-2010, 06:28 PM
  2. GetIcon from jTextPane
    By Gudradain in forum AWT / Swing
    Replies: 4
    Last Post: 11-26-2008, 04:26 AM
  3. how to insert tables into JTextPane
    By osval in forum AWT / Swing
    Replies: 1
    Last Post: 07-29-2007, 10:11 AM
  4. Transparent JTextPane
    By Ada in forum AWT / Swing
    Replies: 1
    Last Post: 05-31-2007, 10:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •