Getting jeditorpane to scroll to a piece of text

I am highlighting text in a JEditorPane and can't figure out how to get the pane to scroll so the hightlighted text is visible.
Any ideas?
Thanks

search -> no answer
browse main page -> easy answer
I feel silly. I just modified this a little:
text.setCaretPosition( text.getDocument().getLength() );
http://forums.java.sun.com/thread.jsp?forum=57&thread=422783&tstart=0&trange=15

Similar Messages

  • Getting the Physical Length of a Piece of Text (in mm etc.) in Javascript

    I'm trying to write a script in Indesign CS5 (Windows) that can measure the physical, 'rendered' length of two pieces of text of similar length (in mm etc.), calculate the average length of the two, and adjust the tracking/horizontal scale of one or both of the pieces of text so that the physical length of both texts are the same.
    I need a script because this task must be done thousands of time in a long document.
    I'm struggling to find a way to access the 'rendered' length of a piece of text in Javascript.
    I know among the attributes of a text box is whether the text has overrun. So I could copy the text to a special text-box, and use a for loop to reduce the dimentions of the text box, 1mm at a time, until the text box overruns, thus determining the length..
    I could also get the length of a rendered string using python with it's built in GUI toolkit Tkinter:
    http://stackoverflow.com/questions/2922295/calculating-the-pixel-size-of-a-string-with-pyt hon
    And then have an indesign script that takes some data from the python script and sets the tracking/horizontal in Indesign with some fudge factors.
    Both ideas seem like real kludges.
    Any other suggestions?
    Many thanks
    David

    You can simply iterate through each line in text to get the widest line. Something like this:
    Main();
    function Main() {
        var text = app.selection[0],
        minLength, maxLength, start, end;
        for (var i = 0; i < text.lines.length; i++) {
            start = text.lines[i].characters[0].horizontalOffset,
            end = text.lines[i].characters[text.lines[i].characters.length-1].horizontalOffset;
            if (minLength == undefined || start < minLength) {
                minLength = start;
            if (maxLength == undefined || end > maxLength) {
                maxLength = end;
        var length = maxLength - minLength;
        $.writeln(length);
    But this approach seems to be a little less precise than creating outlines since (I guess) it measures up to the beginning of the last character; discretionary hyphens, line brakes, etc. are not included into the measurement.

  • How to get the Horizontal Scroll Bar for a Table?

    Hi All,
    As per my requirement, I am displaying several records in a Screen in a Tabular Format. But here I have to show 21 Columns in that table which is too high. I am able to display it but due to it I am getting a Horizontal scroll bar for the whole screen since all the columns are not getting displayed in the normal window screen space. But its looking too odd since once I am scrolling it to right the columns are getting displayed but the above Header Bar and Global buttons are not displaying, they are bound to the normal screen space.
    Is there a way to have a Horizontal scroll bar only for that table instead of the entire screen so that on scrolling that bar only the table rows will beshifted ant got displayed?
    With Thanks
    Kumar Gautam

    try this approach.
    include a raw text item before and table item.
    include the appropriate HTML tags in raw text item to enable horizontal scroll
    --Prasanna                                                                                                                                                                                                                                                                                                                                   

  • When I boot up my Mac Pro, I get a small black puzzle looking piece on the lower right side of my thunderbolt

    Brand new Mac Pro, 2 thunderbolt monitors;
    I get a small black puzzle looking piece on the lower right side of my  1st thunderbolt monitor when I boot up. It goes away once the computer fully boots, it is only on  there for a second or so. Does anyone have a similar issue?
    These are only 1 month old.

    It has been seen before, when hardware was malfunctioning:
    Re: hello, I turn on my mac and I see a figure over the right part of the screen, do anybody knows what is that?
    Re: bootup symbol

  • When I turn on my ipad2 it won't scroll in any direction and there is a voice explaining everything i do. How do I get it to scroll and turn the voice off

    When I turn on my Ipad2 it won't scroll in any direction and there is a voice explaining everything you do. How do get it to scroll again and turn off the voice. I have tried to reset it both ways and when I go to settings > general I don't see a reset button.

    Settings>General>Accessibility>VoiceOver>off

  • I have a new mac pro and can't get a side scroll bar.  What can I do to get this?

    I have a new mac pro and can't get a side scroll bar.  How can I get this?

    The scroll bar is now set to appear automatically when you start scrolling with a trackpad or scroll wheel mouse. If you are using an mouse without a scrolling device, you should change a setting.
    In System Preferences, click General, and in the Show Scroll Bars section, click the option for how you want it to work. If you want to see them all the time click "Always."

  • Wpf/webbrowser:-how to get height,width,scroll height and scroll width of render html/xhtml/xml pages.

    hi I am using to web browser control to get  height,width,scroll height and scroll width in wpf c#.
    Could You please tell me how to achive this information if .pages contain this css on body.
     style="-webkit-column-width:800px;  margin-right:800px; -moz-column-width: 800px; column-width: 800px; -webkit-column-gap: 0px; -moz-column-gap: 0px; column-gap: 0px; -webkit-column-rule: 0px solid #000;-moz-column-rule: 0px solid #000;column-rule:
    0px solid #000; height:800px; overflow:visible !important; ; margin:0px; -moz-margin:0px;-webkit-margin:0px;display:block;"
    I have to get height,width,scroll height and scroll width  on on complete event.
    this is MainWindow.xaml page
    <Window x:Class="WPFWebBrowserInvokeScript.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="820" Width="820" Loaded="Window_Loaded">
        <Grid>
            <WebBrowser HorizontalAlignment="Left"
       Height="800"
       Margin="10,10,0,0"
       VerticalAlignment="Top"
       Width="800"
       Name="MainBrowser"/>
            <!--<Grid x:Name="grid1"></Grid>-->
        </Grid>
    </Window>
    this  MainWindow.xaml.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using System.IO;
    namespace WPFWebBrowserInvokeScript
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
            public MainWindow()
                InitializeComponent();
            private void Window_Loaded(object sender, RoutedEventArgs e)
                string strHtml = "";
                using (StreamReader sr = new StreamReader("D:/epubunzip/ePub2_Sample03a_USgovernment_SE_Gr9-12_EN_U1/OPS/9780547451381_c01.html"))
                    strHtml = sr.ReadToEnd();
                    strHtml = strHtml.Replace("<body>", "<body  style=\"-webkit-column-width:800px; overflow:visible !important;  -moz-column-width: 800px; column-width: 800px; -webkit-column-gap:
    0px; -moz-column-gap: 0px; column-gap: 0px; -webkit-column-rule: 0px solid #000;-moz-column-rule: 0px solid #000;column-rule: 0px solid #000; height:800px; ; margin:0px; -moz-margin:0px;-webkit-margin:0px;display:block;\">");
                    string str = "<script> function execScript(){return document.body.scrollWidth;}</script></head>";
                    strHtml = strHtml.Replace("</head>", str);
                    byte[] bytes = Encoding.UTF8.GetBytes(strHtml);
                    MemoryStream ms = new MemoryStream();
                    ms.Write(bytes, 0, bytes.Length);
                    ms.Position = 0;
                    MainBrowser.NavigateToStream(ms);
                    //MainBrowser.NavigateToString(strHtml);
                    MainBrowser.LoadCompleted += new LoadCompletedEventHandler(MainBrowser_LoadCompleted);
            void MainBrowser_LoadCompleted(object sender, NavigationEventArgs e)
    //here I am trying to get  height,width,scroll height and scroll width
    //It's gtting wrong info
              WebBrowser webBrowser = (WebBrowser)sender;
                //mshtml.htmld webDocument = (mshtml.HTMLDDElement)webBrowser.Document;
                //mshtml.HTMLBody webBody = (mshtml.HTMLBody)webDocument;
                //    var dd = webDocument.InvokeScript("execScript");
                //    //  string script = "document.body.style.overflow ='hidden'";         
                //    // var dd = webDocument.InvokeScript("execScript", new Object[] { script, "JavaScript" });
                //    var elems = webBrowser.Document.GetElementsByTagName("body");
                //    System.Windows.Forms.HtmlElement webBody = (System.Windows.Forms.HtmlElement)webDocument.Body;
           

    >>if i am rendering html from MemoryStreamor string in webbrowser control in wpf It's not applying this css
    Yes it does. If you for example add background-color: yellow; to the stlyle you will see that the page turn yellow:
    strHtml = strHtml.Replace("<body>", "<body style=\"-webkit-column-width:800px; background-color: yellow; overflow:visible !important; -moz-column-width: 800px; column-width: 800px; -webkit-column-gap: 0px; -moz-column-gap: 0px; column-gap: 0px; -webkit-column-rule: 0px solid #000;-moz-column-rule: 0px solid #000;column-rule: 0px solid #000; height:800px; ; margin:0px; -moz-margin:0px;-webkit-margin:0px;display:block;\">");
    If the styles doen't get applied as expected it is a browser issue. The WebBrowser control emulates Internet Explorer in IE7 rendering mode by default.  You will have to change some registry settings to change this behaviour. Please refer to the following
    links for more information:
    http://weblog.west-wind.com/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/cf66e0cd-ab6f-45b8-b230-1d78f26670d2/opening-links-from-wpf-webbrowser-control-in-default-browser-instead-of-ie?forum=wpf
    -moz-column-width only works in FireFox for example.
    You may also navigate to an actual page and inject some javascript function that for example adds the styles to the body element dynamically or set the style properties of the body element directly:
    private void Window_Loaded(object sender, RoutedEventArgs e)
    MainBrowser.Navigate(@"E:/Epubs/ePub2_Sample05_Biology_SampleChapter_EN/OPS/ch01.xhtml");
    MainBrowser.LoadCompleted += new LoadCompletedEventHandler(webb_DocumentCompleted);
    private void webb_DocumentCompleted(object sender, NavigationEventArgs e)
    WebBrowser webBrowser = (WebBrowser)sender;
    dynamic doc = webBrowser.Document;
    //int _scrollWidth = (int)webBrowser.InvokeScript("execScript");
    //mshtml.HTMLDocument webDocument = (mshtml.HTMLDocument)webBrowser.Document;
    mshtml.HTMLScriptElement script = (mshtml.HTMLScriptElement)doc.createElement("script");
    script.setAttribute("type", "text/javascript");
    script.innerHTML = "function doSomething(){ /* do something here... */ }";
    //add script to the head
    dynamic head = doc.getElementsByTagName("head")[0];
    head.appendChild(script);
    mshtml.HTMLBody body = (mshtml.HTMLBody)doc.getElementsByTagName("body")[0];
    body.style.background = "yellow";
    //set any body.style property here...
    webBrowser.InvokeScript("doSomething");
    That's about it as far as WPF is concerned.
    Please remember to mark helpful posts as answer and/or helpful.

  • How do I get to the start of a really long text message conversation without scrolling through them all? Thanks

    Hi. How do I get to the start of a really long text message conversation without having to scroll through and load earlier messages repeatedly?  Thanks

    click on the top of the screen (the top bar/clock sectionish).  Hope i helped

  • Why do i get hesitation when scrolling

    When using Safari, after a while, I get hesitation when scrolling, and also when typing, or doing almost anything.  If I restart, everything is fine for a finite period of time.  Then it gets "sluggish" again.  Why is this?  How can this be remedied?  Thanks for any help you can give.

    This is what I have and how it is configured.

  • Getting lyrics to scroll, like karaoke??

    Is there a way to get lyrics to SCROLL, like a karaoke machine? So that they go alone with the music? I understand you can paste your lyrics into the ipod nano, but I wanted to know if there was a more automated way to do it, such that they would correspond with the music. You can email me directly at [email protected]

    There is no auto scrolling for the lyrics
    You have to scroll it yourself

  • When you have a list or blog within a box on a page, how do you get it to scroll within the box.

    When you have a list or blog within a box on a page, how do you get it to scroll within the box?

    Thanks so much!  Whatever I was trying only worked randomly. You made my day!

  • Mouse getting stuck in scrolling function in scroll boxes

    Hi, as the title says, occasionally the cursor gets stuck in scroll mode, where i can't move the cursor independently, the window just scrolls when i move the trackpad up/down. This only happens with the trackpad on my macbook, but when i use a mouse, there aren't any problems. I'm guessing it's just a function I don't know about that I accidentally activate, but I can't find it!
    any help is appreciated! thanks, joe

    Try going to System Preferences > Keyboard & Mouse > Trackpad and then unclick "Ignore Accidental Trackpad Input." That might fix your problem. It fixed mine when the same thing was happening to me.
    Zeb
    EDIT: Just beware that it WILL pick up "accidental trackpad input" when you turn that off. So when typing, try not to get your hands too close to the trackpad.

  • How to get rid of paragraph breaks in a lengthy text instead of manually

    I have imported a large piece of text - it is very narrow and has many paragraph breaks I guess you call it - or return breaks. I started doing it manually but it is a nightmare. Is there an easier way to do it? I snooped around and tried a few things but cannot seem to get this to work. I have a lot more work to do. Thanks again.

    Position the mouse pointer after the last printed character of a paragraph. Press the mouse button and hold it while you drag down over several of the empty lines. Release the mouse button. Simultaneously press command+C keys (then release) to copy the selection to the clipboard. Simultaneously press command+F keys (then release) to open the Find&Replace dialog. Click once in the "Find:" window, then press command+V keys (then release) to paste the contents of the clipboard there. Click in the "Replace:" window then press "Return" to enter a single carriage return. Click on the "Replace & Find' button.

  • I accidently cut a piece of text out of a mail message

    I accidently cut a piece of text out of a mail message the copied a different piece of text with out thinking is thee any way to get the first piece of cut text back?

    Welcome to Apple Discussions!
    Mail supports multiple undos. Keep on undoing from the Edit menu! Not sure how far back that undo buffer is, but keep on trying. If it doesn't work, test it so you know for the future.

  • Join multiple pieces of text

    Does anyone know of a script that will take little pieces of text in CS4 & CS5, and join them into one piece so that the text is easier to edit? I've tried joining the text by selecting it, cutting it , and putting it into a text area, but the type often gets scrambled doing it this way.

    There are a couple of scripts already about that do this… Is your broken up text from PDF where the kerning shatters it? This link has 2 examples:
    http://ajarproductions.com/blog/adobe-extensions/

Maybe you are looking for