Getting a single line from a JTextArea

I have a JTextArea with a fixed size. I've used the .setLineWrap(true) and .setWrapStyleWord(true) on this JTextArea, so when the user types in some text, that's longer that the JTextArea, it will wrap unto the next line. I need to get each visible line from the JTextArea. That is not each line of text, that is seperated by a newline (when the user type Enter), but every line, that is visibly seperated in the JTextArea.
How can i do that.

The javax.swing.text.Utilities class can help:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
public class TestUtility extends JFrame
     public TestUtility()
          final JTextArea textArea = new JTextArea( "one two three four five", 5, 10 );
          textArea.setLineWrap( true );
          textArea.setWrapStyleWord( true );
          JScrollPane scrollPane = new JScrollPane( textArea );
          getContentPane().add( scrollPane );
          textArea.addCaretListener( new CaretListener()
               public void caretUpdate(CaretEvent e)
                    int pos = textArea.getCaretPosition();
                    try
                         int start =  Utilities.getRowStart(textArea, pos);
                         int end =  Utilities.getRowEnd(textArea, pos);
                         System.out.println( start + " : " + end );
                    catch (BadLocationException ble) {}
     public static void main(String[] args)
          TestUtility frame = new TestUtility();
          frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
          frame.pack();
          frame.setVisible(true);

Similar Messages

  • Getting the visible lines from a JTextArea

    I'm using a JTextArea with a fixed size. I've used the setLineWrap(true) and setWrapStyleWord(true) methods on this JTextArea, so when the user types in some text longer than the visible width, it will wrap into the next line. I need to get each visible line from the JTextArea to create a String array of text lines.
    I mean visible text lines (lines visibly separated in the JTextArea), not real text lines separated by a line break character as "\n".
    How can I do this?

    This information is supposed to be contained in the View information of the component. But as far as I can tell it doesn't work for a JTextArea.
    So if you can use a JTextPane then check out the "getWrappedLines" method in this posting:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=608220
    Basically, a View exists for each line in the Document and then each line may have multiple views if the line needs to wrap. So the basic code just count the number of views within each line but you can change the code to get each view separately. Once you have each view you can get the start and end of the text from the document that this View represents.
    Or if you need to use a JTextArea then you can calculate the starting offset of each each line with respect to the model. You can use the viewToModel(..) method to get the starting offset of each line. We know that each line in a text area is a fixed height, so the starting offset of the first line would be modelToView(0, 0); If the line height is 16, then the starting offset of the second line would be modelToView(0, 16), etc. Once you know the starting offset of each line you can subString out the text for each line.

  • Read to get the last line from a File

    Hi
    I am sending in a clarification , hoping that I get an efficient solution from the group, should somebody have come across this scenario and implemented.
    How to read or get the last line from a text file , which usually have a no of records, without actually reading or looping through all the lines
    I know there is some solution with the RandomAccessFile, but given there can be some encoding issues or so.
    Please let me know if somebody have implemented the same.
    Thanks n advance

    The character encoding could, indeed, be an issue especially with UTF-8. I think what I'd do is to create a byte array with the encoded, expected end of line sequence in it and work on the file in bytes. For example, seek to the last 100 bytes of the file, read those bytes and look for an EOL sequence backwards. If not found read the previous 100, 200, 400 bytes etc. until you do find an end of line. Then seek to after the EOL and read normally. Remember an EOL sequence might cross a boundary.
    UTF-8 would be a problem, especially with a unix format file because you might mistake part of a multi-byte sequence for '\n'. To be reliable on UTF-8 you'd need to go back three characters looking for sequence start markers (has the previous character got the top bit set, or the one before that the first two bits set, or the one before that the top three bits). Or you could just react to an encoding exception and try another position.

  • Unable to release planned order for single line from MRP workbench

    Hi
    We are unable to release planned order for single line from MRP Planner workbench,but Select All For Release is working for all the lines for the item
    User want to release a specific line but no new requisition is generated
    It is highly appreciable if anyone could help to resolve this issue
    Appreciate the Help
    Regards
    VKPK

    It sounds like the release goes through in the workbench but the requisition does not show up in source - is this correct? If so I would check item attributes / flags for purchasing and buy. also have found some items require a purchase price to be populated in master and org

  • Is it possible to get a single frame from a video taken on iPhone?

    Help!!! I really need to get a single picture out of a video I took on my iPhone. Someone please tell me it's possible :)

    very easy:
    1. pause the video on the frame you want
    2. hold the home button and press the off switch at the top (like a shutter release on a camera)
    3. the screen shot will appear in your photos
    here is a frame from 'Apollo 18'

  • Getting a single value from an array collection

    I have an array collection that was created from an XML file
    through the HTTP Service. One of the nodes in the XML file was
    product_number and I can display all of the items in this node in a
    datagrid so I know the array has the name of the node in it.
    I would like to be able to retrieve a single item from the
    array collection (e.g. a product_number = to xxx) and assign it to
    a variable.
    I would also like to be able to assign all the items in a
    particlur column (e.g. all product_numbers) to separate variables
    at the same time.
    Any help would be greatly appreciated.

    You can apply a filterFunction.
    Or you can do it the brute force way: loop over the elements,
    and test for the value you want.
    As far as putting values into variables, I am not sure what
    you want.
    And this is not a Flex Builder question and should go in the
    General Discussion forum.
    Tracy

  • How to get a single table from a .db file

    Hello,
    We have taken a backup of our whole schema into a .db file. and by mistake one of our table in that schema got truncated. Is there any way we can restore only that table from the .db file?
    Please help.
    Thanks
    Ramesh

    It's not so easy. You could perform a point-in-time recovery of the whole database, where point-in-time is the moment just before the table was truncated. Big disadvantage is you lose all other changes made after the truncation,too. Or you restore to an auxiliary database, export the table and import it back into the source database.
    Werner

  • How can I get Number of Lines from internal table?

    Hello at all,
    i have in my Report a internal Table, which have many KUNNR.
    For example the internal Table:
    MANDT.......KUNNR......NAME.........FIRSTNAME........CITY
    ...040..........12345.........Owen............Michael........Liverpool
    ...040..........12345.........Owen............Michael........Liverpool
    ...040..........99999.......Johnson.......... Jeffrey........London
    ...040..........12345.........Owen............Michael........Liverpool
    ...040..........55555.......Hardley.......... Kingston.......Birmingham
    I want to know, how many same KUNNR are existing in the internal Table?
    In my example i need the result 3, because their is existing 3 times the Kunnr 12345 in the internal Table.
    Have anyone an idea, how can I resolve this problem?
    Edited by: Thomas Zloch on Jun 21, 2010 2:55 PM - one question mark at a time is sufficient

    Hi,
    1.Create two internal tables of same type and sort according to Kunnr then Delete the
    adjusent duplicates by comparing KUNNR
    2.Sort the table by KUNNR and use ON change of Concept in that Just increment the counter.
    I am writing the sample logic here.
    tables kna1.
    data: t_kna1 type table of kna1,
             w_kunnr type kna1-kunnr,
             counter type i," Holds No.of KUNNRs in the T_kna1
             t_kna2 type table of kna1.
    select * from kna1 into table kna1 up to 100 rows.
    t_kna2[] = t_kna1[].
    delete t_kna2 by kunnr.
    delete adjusent duplicates from t_kna2 by comparing kunnr."1st Method
    read table t_kna2 transporting no-fields.
    counter = sy-tfill."1st Method
    loop at t_kna1 into kna1."2nd Method
    at first.
    w_kunnr = kna1-kunnr .
    counter = 1.
    endat.
    if w_kunnr ne kna1-kunnr.
    counter = counter + 1.
    endif.
    endloop.
    Note : Here I used a sample table KNA1 in this there are no Duplicates of KUNNR .

  • What is the best way to get a single bookmark from my Laptop to iPhone?

    Also, is there specific HTML formatting that makes it easy for iPhone to pick a telephone number out of a web page?

    Hi Bill,
    If you sync your bookmarks then the one you want will be on your iPhone. If you don't sync your bookmarks I would imagine you would have to enter it in the web browser on your phone and then add it to your bookmarks right on the phone.
    I don't know about the HTML, but quite frequently if you click on a phone number on a web page, the phone will ask you if you if you want to call it. If you do, then you can add it to your contacts.

  • Adobe form from webdynpro : Getting a single row in the table

    Hello,
    I have a scenario in which I have to create a adobeform from webdynpro application.
    I have created the form and have the context designed in place.
    I am facing a problem in the table I have in my adobeform.
    I am adding rows to this table dynamically using a button using "addInstance"
    Now on the webdynpro side , when I try to read this table I get a single row from this table.
    This row is always the first row of that table.
    I checked the following things from blog   /people/juergen.hauser2/blog/2006/09/12/avoiding-common-mistakes-when-using-tables-on-sap-interactive-forms  , i.e. :
    Cardinality of the node.
    Tick on the option "Repeat Row for Each Data Item".
    But still no success.
    With deadlines to catch I had to post this question after trying a lot.Please help.

    Hello Otto,
    I had found this link before and used the same solution , but unfortunately is taking a long time.
    Now what I am doing is :
    1. I append 10 rows into the table then bind it to the node
    2. Then on the adobe form I have removed the check on "Add row for each line item" because of which it shows only 1 row 
         on the form.
         Now I add rows dynamically, but this puts a limit on the number of rows can be added to the table i.e. 10.
    But this again has added problems like while displaying the form or modifying I hav to handle it seperately and cannot use the same form as it is.( as I have removed the tick for "Add row for each line item" ).
    Thanks,
    Omkar Mirvankar

  • Read Lines from, JTextArea

    Hi there,
    I'm trying to save the text from a JTextArea as a file. It all work fine, except the file is written as on long string. Is there any way around this? I was going to read the text line by line, add it to a Vector and then write the file from the Vector, but how do u read just on line from a JTextArea.
    All I can find is .getText - but that dosn't do the trick.
    ANy suggestions Dukes?

    well, yes but the problem is:
    I load one .txt file (or similar) into the JTextArea, then u change it round a bit and click on save.
    This is when the .getText method comes into play, unfortunately it seems to read the whole area as one string (where line-breaks appears as little black squares).
    Is it possibly the FileOutput sequence that's the problem?
    (there's no "\n" in the loaded text)

  • Pick Release single line in a sales order

    Hi All,
    I want to pick release a single line from a sales order i.e if i have a sales order which has 3 lines and i want to pick release first line using Release Sales Order form of OM R12. I am giving the delivery detail id in Release Sales Order form, it is creating the concurrent request but it is not pick released. Please suggest what are the other parameters that has to be given so that i can pick release a single line of a sales order.
    Thanks and Regards,
    Mahesh

    Hi,
    Sorry for late reply. You have to use WSH_DELIVERY_DETAILS_GRP.delivery_detail_action.
    Script is as follows.
    DECLARE
    cursor lcu_det is
    SELECT released_status,
    organization_id,
    container_flag,
    source_code,
    lpn_id,
    CUSTOMER_ID,
    INVENTORY_ITEM_ID,
    SHIP_FROM_LOCATION_ID,
    SHIP_TO_LOCATION_ID,
    INTMED_SHIP_TO_LOCATION_ID,
    DATE_REQUESTED,
    DATE_SCHEDULED,
    SHIP_METHOD_CODE,
    CARRIER_ID,
    shipping_control,
    party_id,
    line_direction,
    source_line_id,
    move_order_line_id
    FROM wsh_delivery_details
    WHERE delivery_detail_id = 4369052;
    l_rec_attr_tab WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Attr_Tbl_Type;
    lr_action_prms WSH_GLBL_VAR_STRCT_GRP.dd_action_parameters_rec_type;
    lr_dummy_defaults WSH_GLBL_VAR_STRCT_GRP.dd_default_parameters_rec_type;
    v_msg_index_out NUMBER;
    x_msg_count NUMBER(10);
    x_return_status VARCHAR2(10);
    x_msg_data VARCHAR2(4000);
    x_action_out_rec WSH_GLBL_VAR_STRCT_GRP.dd_action_out_rec_type;
    BEGIN
    FND_GLOBAL.apps_initialize(1788,50577,660);
    lr_action_prms.caller := 'WSH_PUB';
    lr_action_prms.action_code := 'PICK-RELEASE';
    l_rec_attr_tab(1).delivery_detail_id := 4369052;
    open lcu_det;
    fetch lcU_det into
    l_rec_attr_tab(1).released_status,
    l_rec_attr_tab(1).organization_id,
    l_rec_attr_tab(1).container_flag,
    l_rec_attr_tab(1).source_code,
    l_rec_attr_tab(1).lpn_id,
    l_rec_attr_tab(1).CUSTOMER_ID,
    l_rec_attr_tab(1).INVENTORY_ITEM_ID,
    l_rec_attr_tab(1).SHIP_FROM_LOCATION_ID,
    l_rec_attr_tab(1).SHIP_TO_LOCATION_ID,
    l_rec_attr_tab(1).INTMED_SHIP_TO_LOCATION_ID,
    l_rec_attr_tab(1).DATE_REQUESTED,
    l_rec_attr_tab(1).DATE_SCHEDULED,
    l_rec_attr_tab(1).SHIP_METHOD_CODE,
    l_rec_attr_tab(1).CARRIER_ID,
    l_rec_attr_tab(1).shipping_control,
    l_rec_attr_tab(1).party_id,
    l_rec_attr_tab(1).line_direction,
    l_rec_attr_tab(1).source_line_id,
    l_rec_attr_tab(1).move_order_line_id;
    close lcu_det;
    WSH_DELIVERY_DETAILS_GRP.Delivery_Detail_Action(
    p_api_version_number => 1.0
    ,p_init_msg_list => FND_API.G_FALSE
    ,p_commit => FND_API.G_TRUE
    ,x_return_status => x_return_status
    ,x_msg_count => x_msg_count
    ,x_msg_data => x_msg_data
    ,p_rec_attr_tab => l_rec_attr_tab
    ,p_action_prms => lr_action_prms
    ,x_defaults => lr_dummy_defaults
    ,x_action_out_rec => x_action_out_rec);
    IF x_msg_count > 0 THEN
    FND_MSG_PUB.get (
    p_msg_index => 1
    ,p_encoded => 'T'
    ,p_data => x_msg_data
    ,p_msg_index_out => v_msg_index_out);
    IF x_return_status = 'S'
    THEN
    DBMS_OUTPUT.PUT_LINE(x_msg_data);
    END IF;
    END IF;
    END;
    Thanks and Regards,
    Mahesh

  • Ai-cs6 How Do I trace a hand drawn sketch to a single line vector outline?

    So I am basically a brand new user to ai-cs6 and have been working on a project for a friend. I've drawn up the basic components of the logo she wants, all separate individual pieces. My intention is/was to trace in each piece, and scale, rotate, and clean them up according to how the final piece should look. Where I'm running into trouble is that the sketches are not point perfect, meaning there's some shading in the hand drawns, and the lines are rough in areas. I'm trying to avoid redrawing the pieces because we both are really happy with where they're at. What I'd like to do with ai-cs6 and I'm hoping this community of creative individuals can help is to trace very simply a one line vector of the outline of the image. So instead of creating a piece that has stroke straight from the scanned in artwork, I get a single line, with multiple points, that flows the simple shape of the piece. From there it seems it would be pretty simple to just increase the stroke weight and modify the style of line to make it look how we would like. All I've succesfully been able to do so far, with the help of some videos and google searching, is to get a traced image that's basically an outline of the sketch. This is o.k. except that since the sketch has some rough line sections ai-cs6 is adding either a lot of detail and making it look pretty rough, or it's missing entire sections and leaving them blank. Any insight and help into getting this figured would be great, I'm gonna roll with what image trace is giving me so I can give her an image of the logo today, but hoping that I can clean it up and get closer to a finished product by next week. Thank you very much I'm grateful that there are discussion forums like this out there to help users of all skill level continue flowing and working with these awesome adobe products.
    Max

    What you're talking about is generically called autotracing in centerline mode. Most autotrace programs can either try to trace all the way around the areas of dark pixels (outline tracing), or try to trace along the middles of areas of dark pixels (centerline tracing).
    In Illustrator's autotrace settings, for centerline mode, you turn off the tracing of outlines (fills) and turn on the tracing of centerlines (strokes). That's the basic setting. From there, you try to adjust the various threshold settings to get as close to what you want as you can.
    When Illustrator's autotrace feature is set to try to trace centerlines, it also tries to set the vector path stroke weights to approximate the thicknesses of what it interprets as a stroke. So after the autotracing is done,  you can expand it and then globally set the stroke weight to a uniform value.
    Beyond that, no one can really advise you more specifically without seeing the specific image involved. Every image is different.
    Generally speaking, autotracing is crap. It's an amateurish workaround to avoid doing what should really be done: Trace the paths manually with the drawing tools.
    JET

  • Buffered Reader from  a JTextArea?

    Hi everyone,
    can anyone please tell me how i can get a buffered reader from a JTextArea? This is what I would like to do where the following gets displayed in the JTextArea
    Please enter your name: (user enters data here)
    Please enter your id number: (user enters id number here)
    I had coded this using the System.in but now trying to convert to a GUI
    Regards,
    M

    Hi there,
    I can't use get text as I will already have the other data that is written in the text area there as well, so it will get all the text. I need to be able to write stuff and then read the next line from what I have written. For example using my the command prompt:
    static BufferedReader br = new BufferedReader(
                                                     new InputStreamReader(System.in));
    System.out.print("Enter choice : ");
                System.out.flush();
                String choiceStr=null;
                try
                    choiceStr = br.readLine();
                } catch (IOException ioe)
                    System.out.println("Error reading choice.");
                    System.exit(1);
                int choice = -1;
                if (choiceStr.length() > 0)
                    choice = Integer.parseInt(choiceStr);
                switch (choice)
                    case 0: ....
                }On screen it would have wrote Enter choice: (user puts "7" )
    when the 7 and then /r is pressed then it will read in the 7 only.
    Thanks, M

  • How to get a single pulse Using Burst MOde?

    Harlow Peeps! Just want to know how to get a SINGLE pulse generated by the AGILENT 33220A function generator? the results i get it's in the burst MODE and everything is running smoothly and fine! it's just that i want to get a single pulse froM it only and not repeated triggeriong of the pulse...
    thanks! ^^
    cheers!

    hi,
    find attached an example, how to set hp33250a ( ag33xxx )  into burst mode.
    hope this helps........... - play with it - and change it to your needs.
    regards
    Werner
    Attachments:
    hp33250a _burst.zip ‏165 KB

Maybe you are looking for

  • How can I get connection from iMac to TV wirelessly ?

    How can I view photos from my Mac hard drive or from an external hard drive on my TV screen? My Sonia Bravia TV is in another room and has a Wireless LAN adaptor which detects my Router and connects, and also detects an external hard drive connected

  • Problem: Error in WHERE clause. Unrecognized clause or element.

    Hi All, i have a replicat and tried to filter some rows: This was my MAP-Statement in the param-file: MAP GOMS3KT, TARGET goldengate.txlog, COLMAP ( tsid = #IDTIMESTAMP(), syskey = SYSKEY, type = "KT", trxtimestamp = #TRAILJULIANTS(), acquirer = #ACQ

  • Using Exchange 5.5 to authenticate Portal Users

    I have searched through the forums and metalink for examples and/or instuctions on how to successfully use the Exchange 5.5 LDAP directory to authenticate users, to no avail. I have tried a number of different methods with no success. Has anybody out

  • Running report from database package

    Hi, I have a database package and it gets soem details and submits the report using SRW. It has submitted successfully. But the report is not outputed but there is file with extension eps. Can the package pass the user variables?? The package code fo

  • Remove Private Window Option in Safari MacBookPro

    Remove Private Window Option in Safari MacBookPro Hello there, I am trying to remove the Private Window Option in my Safari MBP Version: 10.10.3. I have found the following guide below, but I could not find the "MainMenu.nib" file. Is there a way to