Finding the position of the end of a line in a JTextPane

I'm trying to make a JTextPane which expands horizontally if the text being typed in it reaches the right hand edge. To do this I need to know the position in the Document of the end of the current line.
I've managed to write a method which expands the JTextPane vertically using getEndPosition() in AbstractDocument.
There is an endLineAction in the DefaultEditorKit which moves the Caret to the end of the line but I don't want to move the Caret, just find the position of the end of the line. I did have a method before which moved the Caret to the end of the line, stored the position and moved it back but that wasn't suitable.
I suspected the answer was to do with the View but I can't figure out how the View relates to the JTextPane or Document.
Can anyone help?

Well, personally I don't think its a good idea to keep changing the size of the text pane as text is being typed and I doubt the solution will be as easy as you think.
As you type the text will automatically wrap so it will be a little late trying to change the width after the text has wrapped, which means you would need to increase the width "before" text is typed. But then you have another problem because you don't know how much to increase the width by since a single character could be typed or a string of text could be pasted into the text area (people always forget about pasting when doing stuff like this).
Also if text is removed you would need to iterate through all the line to find the longest line and reset the width.
Anyway the only way to know the width would be to play with the modelToView() method. If you want to find the end of the current line then you can use the Element.
Check out my [Text Utilities|http://www.camick.com/java/blog.html?name=text-utilities] class which might give you some ideas on how to use the Element class and modelToView() method.
which has example of using the above Class and method that might give you some ideas.

Similar Messages

  • My 3 apple products, an imac, a macbook air and a macbook lost their contact with their external hard disks. They were LaCie make. And every time I turn my laptops, I find the positions of the keys on their  keyboards changed.  Why is Apple silent?

    After the latest apple IOS upgrade my 3 apple products, an imac, a macbook air and a macbook, lost their contact with their external hard disks. They were LaCie make. And every time I turn my laptops, I find the positions of the keys on their  keyboards changed.  Why is Apple silent? There are so many people complaining about this issue and expecting Apple to correct this issue that they have created.

    Probably because it's not an Apple issue. I have Lacie EHD's connected to my MBAir and iMac, all work perfectly on Mavericks. In addition I don't have any keyboard issues on any of my Apple products. BTW IOS is only for IOS devices such as iPads, iPods and iPhones, Macs use OS X. The two OS's are seperate  products designed to run on seperate products.

  • Can I change the position of the Get Info window?

    Can I change the position of the Get Info window?

    If you want to open the "Get Info" panel in the center of your screen, define the following Automator service and install it in the "Services" Folder of your User Library. This service will be available when you ctrl-click a file or folder in the pop-up menu and it will open the "Get Info" in the center of the screen.
    Open Automator and select New -> Service.
    Select: Service receives "files or Folders" in "Finder.app"
    Drag a "Run Apple script" action from the Actions pane -> Utilities onto the Workflow
    Paste the following script into the action, after (* Your script goes here *) and before "return input"
              tell application "Finder"
      activate
                        set {d1, d2, d3, d4} to (get bounds of window of desktop)
      open information window of item input
                        set {i1, i2, i3, i4} to (get bounds of information window 1)
                        set position of information window 1 to {d1 + (d3 - i3 + i1) / 2, d2 + (d4 - i4 + i2) / 2}
              end tell
    Save the service and name it e.g. "centeredGetInfo". It will be installed in your library -> Services.
    Now you can ctrl-click any File or Folder, and in the Services Section of the pop-up menu you will see your new service "centeredGetInfo", also in File ->Services in the Finder, when you select a Finder item.
    You can bind this service to a keyboard shortcut in the keyboard preferences and use it like the standard "Get Info"

  • How to make the graph follows the position of the video frame

    Hai..
    I want to open the video (. avi) and graph together in one VI.. The videos and graphs can be controlled (forwarded or rewind) in the desired position.. However, the graph should follow where's the position of the video frame..   The graph generated from the data in excel, after reading data, then there is the processing of signals, such as filter, mean, find the peak, etc.. After that the result will appear in the graph..
    Until now, I've been able to display video and graph.. I'm trying to use WMP and also IMAQ..
    Because I want to show the position of the graph or signal when the video plays, I was making a cursor or a line on a graph that follows the position of the video..
    First, I'm trying using WMP.. I can forward and rewind video using WMP, after that I make a cursor on the graph and the position of cursor I put in the position video.. And then when I run the program, the signal that arises from the right, but the cursor in the graph follow the position of the video (the cursor appears on the left) different side with the signal..
    I also tried using IMAQ when I tried to use the video controls, so the video can be forward or rewind using the slide, and I made a graph control to follow the video.. But the video isn't playing, it just show only images or frame in the video..
    Can we create a graph that can follow the position of the video? (graph can be in forward and rewind just like with video)
    I've tried many ways but until now have not been successful.. can someone help me?
    Any help is greatly appreciated thank you.

    This should do pretty much what you want, assuming that a slider is how you are controlling your video position. You are going to have to play around with it a little but it should give you the basic idea.
    Attachments:
    Slider.vi ‏35 KB

  • Does anyone know why the waveform peak detect function provides accurately the position of the peaks but not the value?

    Does anyone know why the waveform peak detect function provides accurately the position of the peaks but not the value?
    I have been looking at my data at the position indicated by the function as a peak, and it is correct at that place the wave has its peak, but the value provided by the function is higher than the actual value at that point.
    Attachments:
    Test.jpg ‏53 KB

    The help makes it clear that the VI will make a quadratic fit to the data, so the locations are not integers (i.e. not aligned with you exact data). From that analysis, the peak is between two of your points, and slightly above the neighboring data.
    See the coercion dot. Make the "locations" array DBL (Why did you change it to I64, that makes no sense at all!)
    Quote from the help:
    "Locations contains the index locations of all peaks or valleys detected in the current block of data. Because the peak detection algorithm uses a quadratic fit to find the peaks, it actually interpolates between the data points. Therefore, the indexes are not integers. In other words, the peaks found are not necessarily actual points in the input data but may be at fractions of an index and at amplitudes not found in the input array."
    All clear?
    LabVIEW Champion . Do more with less code and in less time .

  • How can I show a value according to the position of the mouse arrow ?

    Hi Everyone,
    I am changing the color of the background of some indicators according to temperature measures. Each background is linked to one temperature. I would like to show the value of a temperature when passing the arrow of my mouse over the indicator. I don't want to over charge the Front Diagram with all of the temperatures.
    Is this possible? The temperature could appear in a unique and fixed indicator, or linked to the arrow,...
    Any help would be great,
    Thanks,
    User
    Solved!
    Go to Solution.

    Hi Ravens and Dan,
    Thanks for your answers.
    Ravens, I would rather not use the arrow position because I need to do this overs 100 indicator, and that would be a bit long. Added to that if I need to change the positions of the indicators (whch I will) that would mean to redefine the positions of the indicators....But perhaps your solution is the only possible?
    Dan, I have taken out and simplified the piece of my program. Setting the value of the indicator to transparent except when the mouse is over the indicator could be an example of presentating the values but I still don't know how to this (without having to define the position of each box)
    Thanks again
    User
    Attachments:
    forum 14 02 10.vi ‏9 KB

  • I'm doing a scan around a line by sampling data 360 degrees for every value of z(z is the position on the line). So, that mean I have a double for-loop where I collect the data. The problem comes when I try to plot the data. How should I do?

    I'm doing a scan around a line by sampling data 360 degrees for every value of z(z is the position on the line). So, that mean I have a double for-loop where I collect the data. The problem comes when I try to plot the data. How should I do?

    Jonas,
    I think what you want is a 3D plot of a cylinder. I have attached an example using a parametric 3D plot.
    You will probably want to duplicate the points for the first theta value to close the cylinder. I'm not sure what properties of the graph can be manipulated to make it easier to see.
    Bruce
    Bruce Ammons
    Ammons Engineering
    Attachments:
    Cylinder_Plot_3D.vi ‏76 KB

  • How to determine the position of a word in a line

    hello
    i want to know the position of a word on which caret is at present or the position of the selected word in a line displayed in the JEditorPane. for example, if this line is displayed
    Java is an Object oriented Language.
    if i select "an" then its position i get must be 3. Select Java postion must be 1 and so on.
    thanx in advance
    -Ashish

    Hi,
    you can use a StringTokenizer to break the result of getText() of JEditorPane into words and simply count them until the caret postion is passed. Add a method like this in your JEditorPane subclass:
    public int whichWord() {
    String delimiters = "\n\t "; // checking for new line, tab and space as word breaks
    StringTokenizer st = new StringTokenizer(getText(),delimiters,true);
    int pos = getCaretPosition();
    int count = 0;
    int len = 0;
    while ((len<pos)&st.hasMoreTokens())
    String s = st.nextToken();
    len += s.length();
    if (delimiters.indexOf(s)==-1) { count++; }
    return count;
    }Hope this helps - not tested, coded on the fly into this textbox.
    greetings Marsian

  • How to get the position of the stem in control valve using slider control in the front panel

    I have created a calibration program for a control valve. Signal (4-20mA) is generated from labview using slider contorl which is given to the valve via DAQ(module 9265) and again the feedback signal from the valve is acquired using DAQ(module 9203).. . There is an input ISO/ISC(Increasing signal to open/ Increasing signal to close) in the front panel.
    ISO would set the output to increase from (4-20)mA further opening the valve
    ISC would set the output to increase from (4-20)mA further closing the valve
    I have doubt, how can i get the position of a stem

    Ravens Fan wrote:
    If the position of the stem is being sent to the PC through a 4-20 mA signal into your DAQ 9203 module, then you just need to do an analog input read in order to get the signal.
    When reading this post, that is what came to mind...  So let's see if both RavensFan & I are trying to understand the same thing...  Are you saying that the position of the stem is linear (or scaled) to the amount of current sent to it?  Meaning a 4mA signal would move it a certain distance, and 10mA would move another given / known distance?  Or are you saying that it is calibrated so that a 20mA signal for a certain duration (ms) would move it a given distance? So the scale would be time and not current unless a lookup table is used to adjust the time duration based on the current being drawn...
    It's just that I am not familiar with solenoid / drive devices that related to current..  To voltage, yes.  To time, yes..  To current, I'm simply saying that I am not familiar with that.  Can you tell us more about this stem (mfg / model designation)?

  • How can I correct the position of the text in TEXTITEM?

    In TEXTITEM Box, some texts are placing on the top.
    The forms version is 6i.
    How can I correct the position of the text in TEXTITEM?

    Hi
    good thread to this problem
    Vertical justification for Text Item
    Thanks
    asp

  • How can I change the position of the tab bar?

    I just can't get used to the tab bar being on top in Firefox 4. I keep closing open pages by clicking on the bookmarks menu bar. How can I swap the position of the two bars?

    Please click the '''Helpful''' button next to the answer that solved your Firefox support issue, '''when you are logged in''', so this thread gets marked as '''Solved''' to help other users who may have this same problem.

  • Can I set the position of the new mail window?

    Each time I compose a new message, the new message window seems to appear at a different place, usually obscuring the main window. I would like to have it always appear to the side of the main window. Can I set this, perhaps in the property list?

    Perhaps something is corrupt that is causing bad behavior for some users and so my comments are unhelpful, but here's some more data to add to this discussion: My Mail.app behaves as George Coghill described above, subsequent message windows open where the previous window was open.
    For example- Close all Mail.app windows so that only the main "Message Viewer" window is open (basically, don't have any emails that you're in the middle of drafting open).  Open a new message, adjust the position as you wish, then close it.  When you open another new message, does it have the same position as the one you just adjusted?  It should.
    However, for me, sometimes it would be off by a few pixels as Thomas A Reed described above.  I realized that this was because I had another compose window open in the background.  So as you troubleshoot, make sure no other compose windows are open, to remove one complication and help isolate the issue.
    Side note: in cases where the original window's height fully extended across the display, the new window would be shifted over to the right only, but not down at all as some apps do (like Mac Word, annoyingly).  Another note: if you maximize the original window, subsequent windows also open maximized and unshifted.
    A corollary to the paragraph immediately above is that if you open say 3 new windows, the second one will be shifted and the third one will be even more shifted.  Let's say you send all 3, and now open a new window, it has the position of the 3rd window.  Annoying.  Yes, it would be nice if it always opened new windows in the exact same position, but Apple likely won't do this since people will get confused and think they lost the window if it doesn't do the shifting.  I guess the take-away is draft one message at a time or maximize your composition windows, otherwise it's going to move :/
    A band-aid solution: When a window isn't positioned how you like it, a quick/simple way to reposition it is with apps like Moom (my favorite), Cinch, Divvy, SizeUp, etc.  While I'm at it I should mention RightZoom, which makes the green zoom button behave like the Windows maximize button, and Cordless Dog Stay, which is great if you connect/disconnect your laptop to a screen causing the window positions to always get disturbed between displays.

  • Can I control the position of the page background image?

    Hi All!
    My simple question: Can I control the position of the background image for example in a user-made style? I mean can I make the position of the image to center rather then tile? If it possible without editing the html code...

    To create a background image for a region create a table nested within that region using the following definition <TABLE WIDTH="100%" HEIGHT="100%" CELLPADDING="0" CELLSPACING="0" MARGIN="0" BORDER="0"> and create an image call integrated into the <TD> tag within said table.

  • To get the position of the characters in the string in sql

    hi all,
    I need to get the position of the characters in the sql , the string like this '10101110111010111' , is it possible to get the answer like this
    pos char
    1 1
    2 0
    3 1
    4 0
    and so on .
    Thanks in advance .

    select level pos,substr(:your_string,level,1) "char"
      from dual
    connect by level <= length(:your_string)Regards
    Etbin
    Edited by: Etbin on 24.9.2011 8:46
    put char between double quotes http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/ap_keywd001.htm#BABCJAEB

  • Change the position of the text field in the report region

    Hi,
    I am having a report region in whch there are 2 buttons which are in the Region Template position #Create# and a
    text field. I added a text field in the same region. I tried to change the position of the text field near the buttons. I
    tried to change "label-Horizontal/vertical alignment" and "Element horizontal vertical alignment". But the postion of the
    text field is not changing. Plz help,
    Thanks,
    TJ

    Hi Andy,
    Sorry to ask this questions.
    1.Where exactly i need to change the HTML code(By uisng the view source?)
    2.My taskname part html code when viewing the source is given below
    tabindex="999"><img src="/i/e.gif" alt="Edit" class="eLink" />
    </a><tr></td><td nowrap align="left">
    <label for="P1_TASK_NAME" tabindex="999">
    <a class="t16OptionalLabelwithHelp" href="javascript:popupFieldHelp('5853137628393530415','676839962625525')"
    tabindex="999">Task Name</a></label></td>
    <td  colspan="1" rowspan="1" align="left" valign="top"><input type="hidden" name="p_arg_names"
    value="5853137628393530415" /><input type="text" name="p_t06" size="10" maxlength="20" value=""
    id="P1_TASK_NAME"  /><a class="eLink" title="Edit" href="javascript:popupURL('f?
    p=4000:371:676839962625525::::P371_ID,FB_FLOW_ID,FB_FLOW_PAGE_ID:5853137628393530415,107,1');" 
    tabindex="999"><img src="/i/e.gif" alt="Edit" class="eLink" /></a></td></table>
    <table summary="" cellspacing="0" cellpadding="0" border="0" width="100%"><tr><td align="right"><table
    cellpadding="0" cellspacing="0" border="0" summary="" class="t16Button">please suggest what changes i need in this code to change the alignment of the task_name text field,
    Thanks,
    TJ

Maybe you are looking for

  • Saving a Form created in Adobe Acrobat 9 Pro

    We create forms for the company to use with Adobe Acrobat 9 Pro, but because others do not have Acrobat 9 Pro they can not save the document after they have filled out the form.  This is causing a big issue for us.  Does anyone know a way that we can

  • Cannot delete old apple device software update file from trash

    I restored a new iPad from an old one and now there is an .ipsw file with the is08 8.0.2 update and I cannot delete it even tried command secure delete and option secure delete. The file is grayed out and says it is in use by another application. Ple

  • In Logic account the operator function is not working properly

    Hi all , When am defiining the logic accounts using a operator as Function ,it is not working at all showing a red border in the cell and not able to update the grid . InValue/Exp-> am using a function -> CurVal > 0 then Result=CurVal else Result ="s

  • Newb - embedding a MOV in a web page and "locking" it?

    I am aiming at producing online tutorials on my web site. I've used iShowU to capture the screen and intend to edit the video in FCP. My question is: when I embed the tutorial video (a MOV file) in my web page, I don't want the viewer to be able to d

  • How to send a mail while saving va02

    Hi experts, i have to send a mail while saving the VA02. The mail id s are maintained in Custom table based on the plant. Regards Ramakrishna L