Number line and position in the line

Hi, is it possible to know the number of the line and the position of the cariet in a textarea?

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
public class UTextComponent
     **  Return the current column number at the Caret Position.
     public static int getColumnAtCaret(JTextComponent component)
          int caretPosition = component.getCaretPosition();
          Element root = component.getDocument().getDefaultRootElement();
          int line = root.getElementIndex( caretPosition );
          int lineStart = root.getElement( line ).getStartOffset();
          return caretPosition - lineStart + 1;
     **  Return the current line number at the Caret position.
     public static int getLineAtCaret(JTextComponent component)
          int caretPosition = component.getCaretPosition();
          Element root = component.getDocument().getDefaultRootElement();
          return root.getElementIndex( caretPosition ) + 1;
     **  Return the number of lines of text.
     public static int getLines(JTextComponent component)
          Element root = component.getDocument().getDefaultRootElement();
          return root.getElementCount();
     **  Position the caret at the start of a line.
     public static void gotoLine(JTextComponent component, int line)
          Element root = component.getDocument().getDefaultRootElement();
          line = Math.max(line, 1);
          line = Math.min(line, root.getElementCount());
          component.setCaretPosition( root.getElement( line - 1 ).getStartOffset() );
          //  The following will position the caret at the start of the first word
          try
               component.setCaretPosition(javax.swing.text.Utilities.getNextWord(component, component.getCaretPosition()));
          catch(Exception e) {System.out.println(e);}
     **  Return the number of lines of text, including wrapped lines.
     public static int getWrappedLines(JTextPane component)
          int lines = 0;
          View view = component.getUI().getRootView(component).getView(0);
          int paragraphs = view.getViewCount();
          for (int i = 0; i < paragraphs; i++)
               lines += view.getView(i).getViewCount();
          return lines;
     public static void main(String[] args)
          final JTextPane textComponent = new JTextPane();
//          final JTextArea textComponent = new JTextArea(5, 30);
//          textComponent.setLineWrap( true );
          textComponent.addCaretListener( new CaretListener()
               public void caretUpdate(CaretEvent e)
                    System.out.println
                         "Column/Line : " +
                         UTextComponent.getColumnAtCaret( textComponent ) +
                         "/" +
                         UTextComponent.getLineAtCaret( textComponent ) +
                         ", Lines : " +
                         UTextComponent.getLines( textComponent ) +
                         ", Wrapped Lines : " +
                         UTextComponent.getWrappedLines( textComponent )
                    SwingUtilities.invokeLater( new Runnable()
                         public void run()
                              System.out.println( UTextComponent.getWrappedLines( textComponent ) );
          JScrollPane scrollPane = new JScrollPane( textComponent );
          JPanel panel = new JPanel();
          panel.add( new JLabel( "Goto Line:" ) );
          final JTextField gotoField = new JTextField(4);
          panel.add( gotoField );
          gotoField.addActionListener( new java.awt.event.ActionListener()
               public void actionPerformed(java.awt.event.ActionEvent e)
                    UTextComponent.gotoLine(textComponent, Integer.parseInt( gotoField.getText()) );
                    gotoField.setText("");
                    textComponent.requestFocus();
          JFrame frame = new JFrame( "Text Component Utilities" );
          frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
          frame.getContentPane().add( scrollPane );
          frame.getContentPane().add(panel, java.awt.BorderLayout.SOUTH);
          frame.pack();
          frame.setVisible(true);
}

Similar Messages

  • I've recently messed up my Mac OS X Lion by deleting Aperture, but I need to get my data out of the computer. And by the way, I've got an important project in Final Cut Pro X. Is there any way I can back it up (including fxs and positions of the clip) ?

    Hello everyone
    I've recently messed up my Mac OS X Lion by deleting Aperture, but I need to get my data out of the computer. I've tried to repair it using DU, but it said I needed to backup all my data and reinstall the OS. How do I backup my data to an external drive?
    And by the way, I've got an important project in Final Cut Pro X. Is there any way I can back it up (including fxs and positions of the clip) ?
    Hope you guys can help me!

    You need to back up 2 folders, Final Cut Events and Final Cut Projects which by default are located on your Movies Folder. You can always check by clicking on a clip inside Fianl Cut X and selecting Show in Finder in the contextual menu for the selected clip.

  • How can i read every"number" value and not only the 1st?

    in the vi only the first "number" value(from the data acquisition)is read in the small loop.how can i make every value to be read?every value must be compared with the "numeric" constant,and,if greater the led must turn on.afterwards,when a value which is less than the "numeric" is found the led must turn off.please answer or send mail to [email protected]
    Attachments:
    oximet5.vi ‏152 KB

    The more I look at your program, the less I understand it.
    Why are you setting number = number in a case if SO2 = ""? number always equals number.
    In your sequence frames 1 and 4, you have no control over which write (date or time) happens first. Just placing one function to the left of another doesn't make it happen first if your wiring doesn't create data dependency. Review the section on Data Dependency in chapter 5 of the LabView User's Manual.
    It looks you're writing to and reading from the same file using Write File and Read Lines from File.vi. Why read back data you just wrote? You have the data on your diagram. If you want to convert it from string to numeric, use a Sring/Number Conversion function from the String palette.
    On Read Lines from File.vi (which I'm not sure you even need), you should use a shift register for the start of read offset rather than a local variable for mark after read (chars.). With a shift register, you can initialize it to 0 when the VI starts. Using a local, if you restart the VI, it will try to startup from where you left off the last time, but you just opened the file for create or replace.
    In your sequence frames 2 and 3, why do you wait for the number to be less than the numeric before writing a carriage return to the file? Also, LabView has a End of Line constant which adapts to the expected value for the operating system. That's generally more flexible than a Carriage Return.
    It looks to me like you're overusing control refnums. You don't need to use a control refnum and a property node to set or read a control's value if you can wire directly to the control's terminal.
    I really don't understand what you're doing with pause and variants. I may be missing the point, but it looks like you made this much more complicated than it needs to be. Why not keep it a boolean?
    For your pause-path, you open the file but never close it. You can lose data that way. You also open it using open function 3, create new file. You'll get an error if the file already exists.
    On a general note, your diagram would be easier to read if you were more selective in how you routed your wires: you have wires on top of wires, wires running under sub-VIs, wires running in the frame of a while loop, wires running under labels.
    I think there's a temptation to overuse sequences. I don't think you need one here. As I mentioned in my earlier message, case structures and shift registers will be more useful to you.

  • How to control the size and position of the region on a page?

    I am trying to create welcome page for my client. I need to create a banner and place the login region in the cente of the page with a fixed width and height. How can I do this.
    Thanks.
    Satya

    Hi,
    Edit your region and go to region header of your region
    and type this
    region header
    <table width ="100px" height = "100px">
    <tr>
    <td>
    region footer
    </td>
    </tr>
    </table>
    you can customize your region position in this way...just use table tag attributes,,i hav egiven example of only height and width but you can use all the table attributes to customize your region like background color,back ground image,alignment etc..
    hope this helps you,
    Regards,
    Jitendra

  • I rented a movie on my phone i put my card number in and everything but the movie said it could not download because there was no space i deleted all my apps it still was not enough. Will i be charged for the movie

    Will i be charged

    Then launch in iTunes and go to Store>View My Account. Enter your password. Go down to Purchase History and click on See All on the right side. Find the movie in the list and click the arrow to the left. Then in the next window - click on Report a Problem.

  • Size and position of the review area

    hi all,
    at the end of a quiz, i get the quiz result with score and
    review area with text indicating whether i pass or fail the quiz.
    For some reason, when i make the review area box smaller, the
    text doesen't wrap with the box. In addition, i also bold the text
    but captivate doesn't reflect that after i published.
    any ideas?
    thanks
    JT

    Hi all
    We shouldn't forget to report this to Adobe as a bug.
    Click
    here to view the WishForm/Bug Reporting Form
    Cheers... Rick

  • My bookmarks mysteriously change folder names and positions in the tree

    Sometimes when I go to add a folder, it gets repeated in different places, or overwrites an existing bookmark folder and mysteriously changes its location. It is very frustrating to try and categorize bookmarks when there is some gremlin or evil elf that confuses things. Category folders get renamed yet have totally unrelated links within it. Why can't bookmarks work like with some semblance of dependability like Windows Explorer does? What the hell is going on with bookmarks?!??

    This can be a problem with the file places.sqlite that stores the bookmarks and the history.
    * http://kb.mozillazine.org/Bookmarks_history_and_toolbar_buttons_not_working_-_Firefox

  • Any idea while updating job and position --I am getting the following error

    Hi, I am trying to update job and position to the existing employee but getting the following error
    Error report:
    ORA-20001: The primary key specified is invalid
    Cause: The primary key values specified are invalid and do not exist in the schema.
    Action: Check the primary key values before attempting to carry out the operation again.
    ORA-06512: at "APPS.HR_ASSIGNMENT_API", line 16616
    ORA-06512: at line 35
    Code which I am using is as below
    declare
    l_assignment_id number;
    l_object_version_number number;
    l_special_ceiling_step_id number;
    LC_EFFECTIVE_END_DATE DATE;
    LC_EFFECTIVE_START_DATE DATE;
    LC_DATETRACK_UPDATE_MODE VARCHAR2(100);
    LC_GROUP_NAME VARCHAR2(1000);
    LC_CONCATENATED_SEGMENTS VARCHAR2(1000);
    L_ENTRIES_CHANGED_WARNING VARCHAR2(1000);
    LC_GSP_POST_PROCESS_WARNING VARCHAR2(1000):=NULL;
    LC_PEOPLE_GROUP_ID NUMBER:=NULL;
    LC_OBJECT_VERSION_NUMBER NUMBER:=NULL;
    LC_SOFT_CODING_KEYFLEX_ID NUMBER:=NULL;
    LC_SPECIAL_CEILING_STEP_ID NUMBER:=NULL;
    LC_GRADE_ID NUMBER:=NULL;
    LC_OTHER_MANAGER_WARNING BOOLEAN:=NULL;
    LC_SPP_DELETE_WARNING BOOLEAN:=NULL;
    LC_ORG_NOW_NO_MANAGER_WARNING BOOLEAN:=NULL;
    LCTAX_DISTRICT_CHANGED_WARNING BOOLEAN:=NULL;
    L_EMP_START_DATE DATE:=NULL;
    J_LOCATION_ID NUMBER;
    J_PAY_BASIS_ID NUMBER;
    J_SEGMENT5 number;
    J_SEGMENT3 number;
    J_SEGMENT2 number;
    J_GRADE_ID number;
    J_PAYROLL_ID number;
    begin
    l_assignment_id := 214;
    hr_assignment_api.update_emp_asg_criteria
    P_VALIDATE => FALSE
    ,P_EFFECTIVE_DATE => TRUNC(sysdate)
    ,P_DATETRACK_UPDATE_MODE => LC_DATETRACK_UPDATE_MODE
    ,P_ASSIGNMENT_ID => l_assignment_id
    ,P_GRADE_ID => J_GRADE_ID
    ,P_POSITION_ID => 5062
    ,P_JOB_ID => 3063
    ,P_PAYROLL_ID => J_PAYROLL_ID
    ,P_LOCATION_ID => 142--J_LOCATION_ID
    ,P_ORGANIZATION_ID => 81
    ,P_PAY_BASIS_ID => J_PAY_BASIS_ID
    ,p_segment5 => J_SEGMENT5
    ,p_segment2 => J_SEGMENT2
    ,p_segment3 => J_SEGMENT3
    ,P_OBJECT_VERSION_NUMBER => LC_OBJECT_VERSION_NUMBER
    ,P_SPECIAL_CEILING_STEP_ID => LC_SPECIAL_CEILING_STEP_ID
    ,P_PEOPLE_GROUP_ID => LC_PEOPLE_GROUP_ID
    ,P_SOFT_CODING_KEYFLEX_ID => LC_SOFT_CODING_KEYFLEX_ID
    ,P_GROUP_NAME => LC_GROUP_NAME
    ,P_EFFECTIVE_START_DATE => LC_EFFECTIVE_START_DATE
    ,P_EFFECTIVE_END_DATE => LC_EFFECTIVE_END_DATE
    ,P_ORG_NOW_NO_MANAGER_WARNING => LC_ORG_NOW_NO_MANAGER_WARNING
    ,P_OTHER_MANAGER_WARNING => LC_OTHER_MANAGER_WARNING
    ,P_SPP_DELETE_WARNING => LC_SPP_DELETE_WARNING
    ,P_ENTRIES_CHANGED_WARNING => L_ENTRIES_CHANGED_WARNING
    ,P_TAX_DISTRICT_CHANGED_WARNING => LCTAX_DISTRICT_CHANGED_WARNING
    ,P_CONCATENATED_SEGMENTS => LC_CONCATENATED_SEGMENTS
    ,P_GSP_POST_PROCESS_WARNING => LC_GSP_POST_PROCESS_WARNING);
    end;
    Thanks in advance
    Rajini

    Please post the details of the application release, database version and OS.
    What HRMS patchset you are on?
    Please see if these docs help.
    Getting "ORA-20001: The primary key specified is invalid" Error Using HR_ASSIGNMENT_API.UPDATE_EMP_ASG_CRITERIA API [ID 737145.1]
    Hr_assignment_api.Update_emp_asg_criteria Gives Ora-20001, Ora-06512 [ID 334491.1]
    Thanks,
    Hussein

  • Where is document number and position changed in CDPOS?

    Hi experts!.
    I think that my question is very easy but I don't know where is it.
    I need to know more details about item changed (item information is in CRMD_ORDERADM_I but I don't know relationship, maybe OBJECT_ID??)
    A lot of thanks in advance.
    Best regards.

    First of all a lot of thank you for your quick answer.
    I have document class, I know it.
    But I don't know document number changed and position changed.
    I re-write my question:
    I have data in CDPOS but details of item changed are in CRMD_ORDERADM_I table. What is the connection between this two different tables? OBJECT_ID no. Maybe OBJECT_ID is a sum of document numberposition... Something like this?.
    A lot of thanks in advance.
    Regards.

  • How to set the size and position of JFrame

    hey all,
    i have a frame and i devide the frame into three panels, i want to make the top panel the lergest and make it square. and the rest two panels in small and in the bottom of the frame.
    could you please help me to set the size and position of the jpanel
    Thanks

    If u want the bottom 2 panels to be on the same level, u can try setting ur content pane to use the BorderLayout and the adding the 3 panels to it with BorderLayout.NORTH(for the TOP panel), BorderLayout.EAST(RIGHT panel) and BorderLayout.WEST(for LEFT panel).
    Don't know if this is what ur looking for, maybe u could describe more on ur layout with a sample image or something?

  • Set specific size and position of preloader's empty movieclip on main stage

    hey, just wondering if it's possible to script an external preloader's empty movie clip to be of a specific size and position on the main stage? here's the script i've got for the preloader so far:
    var my_pb:mx.controls.ProgressBar;
    my_pb.mode = "manual";
    this.createEmptyMovieClip("Portfolio", 999);
    var my_mcl:MovieClipLoader = new MovieClipLoader();
    var mclListener:Object = new Object();
    mclListener.onLoadStart = function(target_mc:MovieClip):Void {
        my_pb.label = "LOADING: " + target_mc._name;
    mclListener.onLoadProgress = function(target_mc:MovieClip, numBytesLoaded:Number, numBytesTotal:Number):Void {
        var pctLoaded:Number = Math.ceil(100 * (numBytesLoaded / numBytesTotal));
        my_pb.setProgress(numBytesLoaded, numBytesTotal);
    my_mcl.addListener(mclListener);
    my_mcl.loadClip("Creative-Outrage_External.swf", Portfolio);
    thanks in advance.

    i could load the movies that way or if i tell my main movie to load the same preloader in an empty movieclip, instead of on the main timeline. however, this way it all looks great, but the buttons on the main timeline won't respond to user events from the external swfs.

  • Actions for Org.Units, Jobs and Positions

    Dear All,
    I know how to create or copy the available actions for Org Units , Jobs and positions thro' the table T777M and run them through PP03.
    Once I do it , when I want to skip some of the relationships it doesnt allow me to , the next page tab is grayed out.
    I mean if we have for ex. a position reporting to a position and because he is, say CEO and I want to skip that relationship I am unable to , how to activate the skip or Next page tab ??
    Regards
    Uday

    Hi,
    Goto table T77IV click on maintain, Click on New Entries >> Enter the subgroup ( PVOB) PV - Plan Verson and OB is for Object you want to maintain the number ranges for eg : 01C for Job. >> Enter and save the record...
    It will take u to the next screen  >> Click on maintain intervals >> Click on Add Intervals >> New screen will appear ... enter the details as below :
    NO    From Number   To Number     Remarks
    01      1                     19999999        This is Object range
    Note : do not enter anything in "Current Number" &  Do not select "Ext"
    I hope this will help you....
    regards,
    Navinkumar

  • HELP! Controlling size and position of new window from applet

    I am totally new to using java. I am making use of a java applet for showing images. Each image may be clicked to open a higher res image in a new window. I want to be able to control the size and position of the new window. The windows need to be different sizes for each image - a couple may be the same size but some will be different.
    I found this:
    <<<<Yes it can (but not after the window has been created). JavaScript can open documents in a new (or an old) window with eg.
    <script>
    window.open("document.url", "window_name", "toolbar=no,statusbar=no,scrollbars=no,resizable=no,width=600,height=400");
    </script>
    The new window will have only the title bar and the frame around the document, nothing else.
    That can be made a function and called from an applet through liveconnect.>>>>
    from a search re window sizes but I need more explicit help with how to put it into my document! This looks like it might work with the exception it doesn't give a position but I could even live without that.
    Am I correct in assuming tha this script goes in the <head> of the document? If I have several different sizes, I would need to have several different but similar scripts but with different window names?
    Do I substitute the actual url where it says "document.url"? What about "window_name"? And what does liveconnect mean?
    Here is a sample from the applet coding I have in place:
    \\\\\<param name="image2" value="barneygargles_th.jpg">
    <param name="link2" value="http://www.barneygargles.com">
    <param name="statusmsg2" value="Barney Gargles Family Restaurant">\\\\\
    Please, I hope someone can help with this! This is driving me crazy!
    Thanks to anyone who can walk me through this one!
    Linda

    I have been searching the internet for more information and it appears that others have been faced with this problem.
    I have found a couple of possible answers but I am not sure how to do them.
    http://forums.macosxhints.com/showthread.php?t=64059
    http://forums.macrumors.com/archive/index.php/t-119915.html
    The first link seems more relavent but I am not sure how to do what it is talking about.
    Can anyone help?
    I have recently moved from a PC to MAC and this problem is really getting in the way of my work.

  • AP Checks - separate check number to each page of the payment

    When the number of invoices flow beyond to the set number of 35, a new check number is being displayed on the check.
    Ex: For the same supplier, the 1st page has a check number 300001 and VOID on the check at the bottom. The next page has check number 300002 and VOID at the bottom and the last page/final page with 300003 and the live check at the bottom.
    Is this an intended functionality? Does anyone have any suggestions as to how to display the same check number on all the pages. Can this be achieved in the report programmatically
    Any help is greatly appreciated.
    Thanks.

    I guess there is a limitation on the number of invoices that can be paid by a single check. It has something to do with the payment document that you are using. Not very sure though!!

  • Business Partner - Number Ranges and Groupings

    Hello,
    A few weeks ago, we are activated RMCA components and activated Telecommunications 6.0 in a sand box client.
    Now we are doing customizing and application of BP.
    We want, and we could, to range BP in number range from 1 to 9999999999, as the costumers appear in our CRM system. But the problem is that we cannot do the same with AR/SD costumers because we already have old AR/SD costumers, not the same person, in the same range and we don't have not used range.
    I know that we can to convert AR/SD costumers groups, but that problem is that we need to convert costumers number.
    How we can open in the same number, the BP and AR/SD costumer? Can we reorganize the old SD costumers?
    We sure that we are not the first company that implement RMCA in the middle of life cycle that already have AR/SD costumers.
    With best regards,
    Galia Ribinik.
    Edited by: Yes SAP Team on Jan 8, 2012 7:53 AM

    RM-CA:  Number ranges and groupings
    Choose the following in the Customizing: Cross-Application Components ® SAP Business Partner ® Business Partner ® Basic Settings ® Number Ranges and Groupings.
    Define the corresponding number ranges externally in RM-CA and ensure that this RM-CA number range includes both the internal and external CRM number range.
    You can choose any name for the group, but it must be the same as the name in CRM.
    SD Customer Mapping
    Choose the following in Customizing: Financial Accounting ® Accounts Receivable and Accounts Payable ® Customer Accounts ® Master Data ®Preparations for Creating Customer Master Data ® Create Number Ranges for Customer Accounts.
    If you also want to create an SD customer during business partner replication, you must create a separate number range for this customer. Assign this number range to the corresponding account group. Choose the following in Customizing: Financial Accounting ® Accounts Receivable and Accounts Payable ® Customer Accounts ®Master Data ® Preparations for Creating Customer Master Data ® Assign Number Ranges to Customer Account Groups.
    ·SD Customer Mapping
    Choose the following in Customizing: Financial Accounting ® Accounts Receivable and Accounts Payable ® Customer Accounts ® Master Data ® Preparations for Creating Customer Master Data ®Define Account Groups with Screen Layout (Customers).
    You must reconcile the account group settings for the business partner with the corresponding field groups for the business partner in CRM. If for example a field in RM-CA is not defined as a mandatory field in CRM, replication will fail if an entry has not been made in this field in CRM.
    Use the PIDE transaction to control which CRM business partner classification is mapped to a specific account group in RM-CA.
    Define the reverse situation here using the corresponding number range grouping.
    ·        Create and assign an SD sample customer
    To generate an SD customer in RM-CA during the business partner replication, you require a reference business partner. This is used as a template during creation.
    Choose the following in the system: Logistics ® Sales and Distribution ® Master Data ® Business Partner ® Customer ® Create ® Sales and Distribution  (Transaction VD01).
    Create the sample customer using the account group described in the preceding step. The system name for the sample customer must start with the letters u201CMUSTu201D (such as MUSTER_TELCO).
    You must also create the sales area data for the customer. Note that you must maintain each sales area used accordingly.
    ·        Assign SD sample customer
    Assign the sample customer in the TCRMBP_REFCUST table (transaction SM30) and define the corresponding determination. If you only want the system to determine a specific sample customer, you can leave the Business partner category, Group and Partner type fields blank.
    http://help.sap.com/saphelp_telecom472/helpdata/en/65/d7a55dadd52348ad73320774783649/content.htm

Maybe you are looking for