How do I select a paragraph element spanning multiple lines

Hi,
I would like to retrieve the text from a JTextArea that surrounds the caret. What I mean by this is that I would like to select out the text around the caret that is a legitimate paragraph not the one associated with PlainDocument.
ie.
blah blah blah
text text <caret> text
text text text text
blah blah blah blah
In this scenario I would like to select out the two lines containing "text." I would like to do this without having to write my own code to parse the document. Your help is greatly appreciated.
Thanks,
John

You could do something like this, although somewhat tedious. Hope it will help!
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.*;
public class ParagraphSelectionTest
  public static void main(String[] args)
    JFrame frame = new JFrame("Paragraph selection");
    frame.setSize(500, 300);
    JTextArea tp = new JTextArea();
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(new JScrollPane(tp), BorderLayout.CENTER);
    frame.getContentPane().add(new JButton(new ParagraphSelectionAction(tp)), BorderLayout.SOUTH);
    frame.setVisible(true);
class ParagraphSelectionAction extends AbstractAction
  private JTextArea m_textArea;
  public ParagraphSelectionAction(JTextArea textArea)
    super("Select paragraph");
    m_textArea = textArea;
  public void actionPerformed(ActionEvent e)
    Element caretElement = ((PlainDocument)m_textArea.getDocument()).
        getParagraphElement(m_textArea.getCaretPosition());
    boolean bStartSet = false;
    boolean bFound = false;
    int nStart = 0;
    int nEnd = 0;
    for (Enumeration enum = ((AbstractDocument.BranchElement)caretElement.getParentElement()).children();
        enum.hasMoreElements(); )
      Element el = (AbstractDocument.LeafElement)enum.nextElement();
      if (!bStartSet)
        nStart = el.getStartOffset();
        bStartSet = true;
      if (el == caretElement)
        bFound = true;
      if (el.getEndOffset() - el.getStartOffset() == 1)
        if (el == caretElement)
          nEnd = nStart;
        if (bFound)
          break;
        else
          bStartSet = false;
      nEnd = el.getEndOffset();
    m_textArea.setSelectionStart(nStart);
    m_textArea.setSelectionEnd(nEnd);
    m_textArea.getCaret().setSelectionVisible(true);
}

Similar Messages

  • How Can I Create One Entry Sheet For Multiple Line Items of A PO

    Please Tell Me How Can I Create One Entry Sheet For Multiple Line Items of A PO

    hi,
    It is not possible to create single Service Entry sheet for multiple PO line items. It is 1 to 1 relation.
    you have to make different service entry sheets for different item of service master.
    regards
    Manish Joshi

  • How do you select all paragraphs using the same style in Pages 5.2?

    I'm trying to find how to select all paragraphs using the same style in Pages 5.2 without any success.  I writing a book and I need to able to adjust all my paragraph styles globally.  I see how upgrade my paragraph style when I do something new, but not how to revert back to the orginal template.
    For example, in my custom template for my book I have 12 font for a review questions paragraph style.  I changed the font size for all this paragraph style to 18 font.  Now I want to change it back to size 12 font.  But I have this paragraph style at the top and bottom of my document.  How to I select all of my review questions style so I can make the font change to all at the same time? 
    I just upgrade to Pages 5.2 from Pages '09. 
    Thanks for the help,
    Rob

    The Pages User Guide might help here.
    Better to post your topic in the Pages designated community > Pages: iWork: Apple Support Communities

  • How do I select a section that has multiple layers?

    I cannot figure out how to do this.
    I work with large city maps. What I need to do is select a rectangular portion of the map, cut it and paste it into a new file. From there I edit that section as needed.  I can use the selection tool and select an area, but what it does is selects the area and any joined lines. This map is over 11 layers thick.
    Every help manual online has only pertained to working with a single layer.
    Is it possible to cut out a rectangular section from a multiple layer project?
    Any help would be appreciated.
    Thank you in advance.

    You can make an artboard to the rectangle shape ( you do this by holdog the shift key down as you drag the artboard tool to make the new artboard within an artboard) you need then select the artbord tool while holding the option key down to drag a duplicate of the artboard and its contents to a portion of the canvas not being used by the orignial document.
    Now some of the items that extend beyond the artboard will be copied as well
    now you can draw a rectangle to match the artbaords dimensions and while it is still selected go to Object>Path>Divide Objects Below.
    the delete the objects out side of the rectangles dimensions including any part of the rectangle youse to divide the objects below with.
    One problem with this method any open path will not be divided so you have to manually scissor them and then delete.
    The good thing about this is that the layers remain intact and all layers are copied.
    Once deleted the extraneous art you can marques select the cropped art and either copy and paste or cut and paste.
    Or just leave it in the document as a separate artboard

  • How to make an editable bulleted list with multiple lines and custom bullets?

    How do I create an editable bulleted list in Acrobat Pro? I've figured out how to add text fields with multiple lines, and how to add a list box, but I don't see the check box for multiple lines in the list box or how to add bullet points. Can someone please give me step by step instructions? Also is it possible to use custom bullet points?

    Is it a text field or a list box field? The two are not the same...
    The bullets are something that the user will have to enter manually (into a text field, they can only select values in a list-box).
    They can use any unicode character, or special characters if the font used for that field allows for it. You can't use images for the bullets, if that's what you mean.

  • How to use parallelism in RMAN script having multiple lines

    Gurus,
    Need your advice on using parallelism in 'BACKUP AS COPY DATAFILE' script having multiple lines.
    I have a script like below:
    CONFIGURE DEVICE TYPE DISK PARALLELISM 10;
    backup as copy datafile '/data1/oradata/PROD/data01.dbf' format '+DATA';
    backup as copy datafile '/data2/oradata/PROD/data02.dbf' format '+DATA';
    backup as copy datafile '/data3/oradata/PROD/data03.dbf' format '+DATA';
    backup as copy datafile '/data4/oradata/PROD/data04.dbf' format '+DATA'; and so on ......
    If I run this script, it runs sequentially. How can I parallely copy the required data files ?
    I have to selectively copy few files in ASM.
    I want to use a single script.
    Please advise.
    Best regards,
    Santosh
    Edited by: 966454 on Oct 18, 2012 11:59 PM
    Edited by: 966454 on Oct 18, 2012 11:59 PM

    Unfortunately, this will not help my case. It may not always be '+DATA'
    I want to know if there is any way to parallelise the multiple statements.
    Script may have :
    CONFIGURE DEVICE TYPE DISK PARALLELISM 10;
    backup as copy datafile '/data1/oradata/PROD/data01.dbf' format '+DATA1';
    backup as copy datafile '/data2/oradata/PROD/data02.dbf' format '+DATA2';
    backup as copy datafile '/data3/oradata/PROD/data03.dbf' format '+DATA3';
    backup as copy datafile '/data4/oradata/PROD/data04.dbf' format '+DATA4'; ........
    or
    backup as copy datafile 1 as '/data1/oradata/PROD/data01.dbf' ;
    backup as copy datafile 2 as '/data2/oradata/PROD/data02.dbf' ;
    backup as copy datafile 3 as '/data3/oradata/PROD/data03.dbf' ; ........
    Regards,
    Santosh
    Edited by: 966454 on Oct 19, 2012 12:33 AM

  • How do I allow a user to enter multiple lines of text within a Text Entry Box?

    I need a text entry box that allows for multiple lines to be inputted with in a Text Entry Box.  How can I make this possible?

    Go to the Options accordion and check 'Show scrollbar'.
    Lilybiri

  • Select query in case of Multiple line items

    Hi Gurus ,
                  I've a doubt in general SQL select query. I want to know , if suppose I've an internal table - itab . I've fetched G/L Account numbers 1st, based on the input selections . Next , I want to loop on those G/L accounts. However, if the G/L account has multiple line items, then I personally use this select query -- >
    loop at itab.
    select <field> from <table> appending corresponding fields of  <itab1> where hkont eq itab-hkont.
    endloop.
    Now, the execution time for this query is longer than expected. The biggest problem here is, i've to sum up the totals as well. So totaling is an added load. I want to reduce the execution time of this. Kindly suggest me some good method in case u have any.
    I've pasted the code which I've written , for u ppl to understand--
    SELECT DISTINCT HKONT BELNR
      FROM BSIS
       INTO CORRESPONDING FIELDS OF TABLE OTAB
        WHERE HKONT IN S_RACCT
    *      AND PRCTR IN P_PRCTR
          AND MONAT IN S_POPER
          AND BUKRS EQ P_BUKRS
          AND GJAHR EQ P_GJAHR
          AND PRCTR IN S_PRCTR.
    ***The code below takes a lot of time to execute.***
    LOOP AT OTAB .
      SELECT DMBTR HKONT
      FROM BSIS APPENDING CORRESPONDING FIELDS OF TABLE CREDITS
        WHERE HKONT EQ OTAB-HKONT
          AND BELNR EQ OTAB-BELNR
          AND MONAT IN S_POPER
          AND BUKRS EQ P_BUKRS
          AND GJAHR EQ P_GJAHR
          AND PRCTR IN S_PRCTR
          AND SHKZG EQ 'H'.
      COLLECT CREDITS.
    ENDLOOP.

    Hi,
    First of all try to avoid doing select into corresponding fields. THis would improve the performance of the program.
    Try to do a single fetch from the BSIS table . fetch the hkont, belnr, dmbtr fields in to a master internal table. Manipulate and play with the data as required.  Don't hit the data base table more than once (unless it is required) . This would improve the performance of your code.
    Try to code this way.
    types: begin of ty_bsis,
                 hkont type hkont,
                 belnr type  belnr_d,
                 dmbtr type dmbtr,
              end of ty_bsis.
    data: it_bsis type standard table of ty_bsis,
             wa_bsis type ty_bsis,
    select hkont belnr dmbtr
              from bsis
              into table it_bsis
              WHERE HKONT IN S_RACCT
            AND PRCTR IN P_PRCTR
              AND MONAT IN S_POPER
             AND BUKRS EQ P_BUKRS
             AND GJAHR EQ P_GJAHR
              AND PRCTR IN S_PRCTR.
    Using the data availabe in the it_bsis, you can manipulate as required.
    Hope this would be helpful
    Regards
    Ramesh Sundaram

  • How to not select an invoice if a certain line item type is present?

    Hi,
    I've created a report that lists all invoices that have a particular line item type on it.  For example, I wanted to produce a revenue report by item type, "P-Tank". So, the invoice table links to the invoice line items table. Each line item record has a "resource id" on it. The resource id links to the resource type table. So, if invoice #8 has, say, three line items and one of them has a resource type of "P-Tank" then I report on it.  Basically, I'm making a report grouped by Resource ID and the Resource ID must by of Resource Type 1, 2 or 3.  So, this report I've solved.
    Now, I want to report on those invoices that do not have either a resource type 1, 2 or 3 item on it.  If I use a formula:
    "Not ({resource_type.resource_type_id} in [1, 2, 3]) that doesn't work because it just omits the line item that is of resource type 1, 2 or 3....but still leaves the invoice on the report with the other line item types. * I want to identify any and all invoices that do not have either a line item resource type 1, 2, or 3 on it.*
    Any help is much appreciated!
    thx,
    Mark

    Hi Abhilash,
    That didn't seem towork.  I'll simplify the example to see if we can find the answer easier this way.
    I'm using two tables: invoice; and invoice_items
    An invoice can have many items on it.
    I don't want my query to select any invoices that have a Tank item on it (Tank has a resource id = 8).
    So, I'll join the invoice table to the invoice_items table:
    invoice.invoice_id = invoice_items.invoice_id.
    The result set looks like the following:
    Invoice #        Invoice Item #     Invoice Resource ID
    22                              1                               8
    22                              2                               9
    23                              1                               5
    So, because Invoice #22 has a line item with resource id = 8 on it I do not want Invoice #22 to appear on the report at all, regardless of what other items and resource id's are on it.
    I have tried joining the two tables in every manner (e.g. inner, outer, not enforced, enforced, etc) and even when I put the condition, invoice_items.resource_id <> 8, it still brings up Invoice #22 but just omits the one line item and leaves the record with resource id 9 (in the example above).  I don't want Invoice #22 to appear at all in the report.
    Does that help clarify the problem?
    thx,
    Mark

  • How do I get DNS searchs to span multiple network interaces?

    Each of our developer machines have two network cards. One is attached to the corporate network the other to a private network. There is a DNS server running on both networks. On our windows boxes we have no trouble doing something like
         ping <device-name-on-corporate-network>
         ping <device-name-on-private-network>
    On our newly purchased Mac Minis running Mavericks 10.9.2 it doesn't work the same way.
    If the service order has the corporate network above the private network then the ping of the corporate device name works but the ping of the private device name doesn't.
    If I swtich the service order so the private network is above the corporate network then the ping of the private device name works but not the coporate one.
    From what I am seeing I believe that on the Macs when a DNS lookup request failure is returned by the DNS server associated with highest active network in the service order list the DNS server associated with next highest active network in the service order is not being sent a DNS lookup request. Is this correct or am I missing a setting someplace?

    I found another the solution was already posted in response to the following question in the discussions group.
    https://discussions.apple.com/message/15095747#15095747
    "Network Service Order Causing Conflict with Private DNS on Local Network"
    KJB_

  • How can I produce a title card with multiple lines of text?

    When I drag "title, multiple lines" to my timeline, the second line appears in a smaller font. When I type all my text on a single line, the title appears in a teeny-tiny font. I want to be able to produce four or five lines of text, all in a readable font. Help!

    2 solutions:
    Costs money and takes work:
    Look for a title plug-in on geethree.com. There are free ones out there too.
    OR.
    Works right now:
    Type your title into the 'scrolling block' title.
    Drop it in and let it render.
    Play it back and pause it when the text is in the middle (or where ever you want it). Choose 'create still clip' from the edit menu. And blamo! You've got multiple lines of the same sized text.
    This might take some experimenting to find what font works best. Some get a little jaggy in the rendering process and look bit-mapped a bit when changed into a still.
    Give it a shot!

  • How to make a long Legend contained in multiple line

    I have a PieChart needs legends. Some of them are very long.
    Is it possible to make long legends written in
    multiple lines? Here is the code for the PieChart and Legend:
    <mx:PieChart id="byMake" height="325" width="100%"
    dataProvider="{make.product}" showDataTips="true" >
    <mx:series>
    <mx:PieSeries field="quantity" nameField="brand"
    startAngle="0" />
    </mx:series>
    </mx:PieChart>
    <mx:Legend dataProvider="{byMake}" horizontalAlign="left"
    />

    "glen08" <[email protected]> wrote in
    message
    news:giem8i$e0j$[email protected]..
    >I have a PieChart needs legends. Some of them are very
    long. Is it possible
    >to
    > make long legends written in
    > multiple lines? Here is the code for the PieChart and
    Legend:
    >
    > <mx:PieChart id="byMake" height="325" width="100%"
    > dataProvider="{make.product}" showDataTips="true" >
    > <mx:series>
    > <mx:PieSeries field="quantity" nameField="brand"
    startAngle="0" />
    > </mx:series>
    > </mx:PieChart>
    > <mx:Legend dataProvider="{byMake}"
    horizontalAlign="left" />
    Try this as your itemRenderer
    package com.magnoliamultimedia.views
    import flash.display.DisplayObject;
    import mx.charts.LegendItem;
    import mx.core.UITextField;
    public class WrappingLegendItem extends LegendItem
    public function WrappingLegendItem()
    super();
    override protected function createChildren():void{
    super.createChildren();
    for (var i:int=0;i<numChildren; i++){
    var child:DisplayObject=getChildAt(i);
    var txt:UITextField = child as UITextField;
    if (!(txt==null)){
    txt.wordWrap=true;
    txt.invalidateSize();

  • How to make a Input Field with multiple lines?

    hey folks,
    i need to make a popup window or a dynpro with 2 input fields, where the user can write on multiple lines. why isnt there such an input field in the screen painter? how can i make this? if i can do this with a dynpro it would be nice but a popup with that feature would be better. didnt found any infos anywhere except for that thread, but its answer didnt work with my dynpro:
    How to make a input/output field with multiple lines
    thx for any helping answer

    i made it just like in that thread but there is an error message telling that gv_custom_container is not declared.
    *  MODULE status_0110 OUTPUT
    MODULE status_0110 OUTPUT.
      CREATE OBJECT custom_container
        EXPORTING
          container_name              = 'TEXT_CONTROL'
        EXCEPTIONS
          cntl_error                  = 1
          cntl_system_error           = 2
          create_error                = 3
          lifetime_error              = 4
          lifetime_dynpro_dynpro_link = 5.
      CREATE OBJECT text_editor
        EXPORTING
          parent                     = gv_custom_container
          wordwrap_mode              = cl_gui_textedit=>wordwrap_at_windowborder
          wordwrap_to_linebreak_mode = cl_gui_textedit=>false
        EXCEPTIONS
          error_cntl_create          = 1
          error_cntl_init            = 2
          error_cntl_link            = 3
          error_dp_create            = 4
          gui_type_not_supported     = 5.
      SET PF-STATUS 'STATUS_0110'.
      SET TITLEBAR 'TITLE'.
    ENDMODULE.                    "status_0110 OUTPUT
    Edited by: rafe b. on Oct 26, 2009 2:56 PM

  • IR column heading spanning mutiple lines colour issues

    Hi,
    I'm using APEX v4.0.2 and thanks to this forum I'm aware of the problem around the banding of column headings in IRs when they span multiple lines. I've cured the problem by adding the following in the page header as suggested in previous postings;
    <style type="text/css">
    .apexir_WORKSHEET_DATA th {
    background: #4682b4;
    </style>
    However, my problem is when I now click on the column heading to use the filters, etc, the colour reverts back to gray again. Is there anything I need to add to change the background colour of the heading when it's clicked?
    Thanks
    Neil
    Edited by: nbradshaw on Jul 28, 2011 10:16 AM

  • Write-Progress -Status span mulitple lines

    Is it possible for Write-Progress -Status to span multiple lines? The status is showing the file being copied and to the location it is being copied to, which can get very long and runs off the console window. I have tried adding `r`n but that doesn't
    work, so I am thinking it is a no, but figured I would ask.
    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.
    Don't Retire Technet

    The progress bar in Write-Progress is based on the width buffer size of the console window. If the width buffer is greater than the actual console window width, then it will spill off of the console.
    There is no way to my knowledge to make this span multiple lines other than to write your own type of progress bar or to make a proxy function for Write-Progress.
    Boe Prox
    Blog |
    Twitter
    PoshWSUS |
    PoshPAIG | PoshChat |
    PoshEventUI
    PowerShell Deep Dives Book

Maybe you are looking for

  • Photoshop 6.0 on Windows 8.1

    On my new computer -Windows 8.1- I want to install my Photoshop 6.0 which run in the past on my older PC's (o.a. VISTA) However I can not install it on it on my new PC. How could I succeed? All suggestions are welcome.

  • Unblock e-mail sender

    I don't know if this is the appropriate forum, but I have a problem.   I recently inadvertently block a e-mail sender.  How can I unblock the sender? This question was solved. View Solution.

  • Select most recent record prior to a target date

    Let's say I have a set of unique records with the following dates: 11/15/08 11/30/08 Is it possible to select only the most recent record prior to a user-entered target date (e.g., 12/1/08)?  So in this case, only the record dated 11/30/08 would be s

  • ADF Skinning - How to identify Skinning Selector Name

    When we do skinning, in the CSS file that is generated by ADF Framework, we are seeing a style named af_commandMenuItem_menu-itemIn order to define, custom properties to this above style, we would need to modify in the custom skinning file as af|comm

  • Mac Book Pro 2011, i need help!!!

    Hello!! After upgrade system to Mountain Lion, my battery life stay so short! 100%= 90 minuts! Why so happend? What can i do for long life my battery? Best regads, Alexey