Removing a highlight based on position in JTextComponent

Hi smartypants' - In the contents of a JTextPane, I have highlighted individual lines of code (using DefaultHighlighter). Now when a user slaps their cursor down into a highlighted area of text, I want that to trigger the removal of a specific highlight. Don't know how to accomplish this though. The Highlighter interface offers a remove method if you happen to keep track of the tag Object returned by a prior call to addHighlight() but I would rather not correlate tags to cursor position (if such a thing can be done?)....
Thx,
Shawn

Position the caret on a highlight and click the 'Remove Highlight' button:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class TextPaneAttributes extends JFrame
     JTextPane textPane;
     public TextPaneAttributes()
          textPane = new JTextPane();
          StyledDocument doc = textPane.getStyledDocument();
          Highlighter.HighlightPainter painter =
               new DefaultHighlighter.DefaultHighlightPainter( Color.cyan );
          //  Set alignment to be centered for all paragraphs
          MutableAttributeSet standard = new SimpleAttributeSet();
          StyleConstants.setAlignment(standard, StyleConstants.ALIGN_CENTER);
          doc.setParagraphAttributes(0, 0, standard, true);
          //  Define a keyword attribute
          MutableAttributeSet keyWord = new SimpleAttributeSet();
          StyleConstants.setForeground(keyWord, Color.red);
          StyleConstants.setUnderline(keyWord, true);
          //  Add initial text
          textPane.setText( "one\ntwo\nthree \nfour\nfive\nsix\nseven\neight\n" );
          //  Change attributes on some keywords
          doc.setCharacterAttributes(0, 3, keyWord, false);
          doc.setCharacterAttributes(20, 4, keyWord, false);
          //  Highlight some text
          try
               textPane.getHighlighter().addHighlight( 4, 7, painter );
               textPane.getHighlighter().addHighlight( 25, 28, painter );
               textPane.getHighlighter().addHighlight( 35, 40, painter );
          catch(BadLocationException ble) {}
          //  Add some text
          try
               doc.insertString(0, "Start of text\n", null );
               doc.insertString(doc.getLength(), "End of text\n", keyWord );
          catch(Exception e) {}
          //  Add text pane to frame
          JScrollPane scrollPane = new JScrollPane( textPane );
          scrollPane.setPreferredSize( new Dimension( 200, 200 ) );
          getContentPane().add( scrollPane );
          //  Add a bold button
          JButton button = new JButton("Remove Highlight");
          getContentPane().add(button, BorderLayout.SOUTH);
          button.addActionListener( new ActionListener()
               public void actionPerformed(ActionEvent e)
//                    new StyledEditorKit.BoldAction().actionPerformed(null);
                    int offset = textPane.getSelectionStart();
                    System.out.println("\nCaret offset: " + offset);
                    Highlighter.Highlight[] highlights = textPane.getHighlighter().getHighlights();
                    for (int i = 0; i < highlights.length; i++)
                         Highlighter.Highlight h = highlights;
                         System.out.println( "Highlight offset: " + h.getStartOffset() );
                         if (offset >= h.getStartOffset()
                         && offset <= h.getEndOffset())
                              textPane.getHighlighter().removeHighlight(h);
     public static void main(String[] args)
          TextPaneAttributes frame = new TextPaneAttributes();
          frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
          frame.pack();
          frame.setVisible(true);

Similar Messages

  • Can you get your cracked iPod Touch screen repaired if you colored the top of it with highlighters? If you can't, how do I remove the highlighter?

    I cracked my iPod Touch screen at the top where the front camera is and colored the cracks in with highlighter. I want to know if I can still get it repaired even if its colored in? If I can't, how do I remove the highlighter?

    If your iPod Touch, iPhone, or iPad is Broken
    Apple does not fix iDevices. Instead, they exchange yours for a refurbished or new replacement depending upon the age of your device and refurbished inventories. On rare occasions when there are no longer refurbished units for your older model, they may replace it with the next newer model.
    ATTN: Beginning July 2013 Apple Stores are now equipped to do screen repairs/replacements in-house on iPhone 5s. In some cases while you wait. According to Apple this is the beginning of equipping Apple Stores with the resources needed to do most repairs for iPhones, iPads, and iPod Touches that would not require major replacements. Later in the year the services may be extended as Apple Stores become equipped and staffed with the proper repair expertise. So, if you need a screen repaired or a broken screen replaced or have your stuck Home button fixed, call your local Apple Store to see if they are now doing these in-house.
    You may take your device to an Apple retailer for help or you may call Customer Service and arrange to send your device to Apple:
    Apple Store Customer Service at 1-800-676-2775 or visit online Help for more information.
    To contact product and tech support: Contacting Apple for support and service - this includes international calling numbers.
    iPod Service Support and Costs
    iPhone Service Support and Costs
    iPad Service Support and Costs
    There are third-party firms that do repairs on iDevices, and there are places where you can order parts to DIY if you feel up to the task. Start with Google to search for these.

  • How do I remove text highlight box in the Notes panel in Presenter 8?

    How do I remove text highlight box in the Notes panel in Presenter 8?  It moves at a different speed than the voice and is distracting.  Better not to have it at all.

    Hi,
    To disable higlighting text in notes pane is not possible in presenter 8.
    However it is possible to disable in presenter 9. 
    Thanks
    Sunil
    Adobe Presenter Engg Team

  • Need to show Counter at report level based on Position

    Chaps,
    one of my HR report requires a counter value based on Position. exactly what i required is want to show the no. of positions count based on Resource type. ( Resource type is a navig. attr of Position). How to define counter for this?
    Thanks.
    Rgds,
    ST.

    Hi Sathish,
       Create a formula variable with replacement with position and attribute resource type. Here write formula.
       Example: (formula variable >= 0)*1+0
    Regards
    Prasad

  • WF based on "Positions" instead of "Users" ?

    Hi guys,
    Is somebody using any WF in SRM that is based on positions instead of users ? 
    For example, if the user A leaves the company, I delete his/her user but not his/her position.
    After, I move the user B (object) into the Position A and this user (b) inherit the pending authorization tasks.
    Thanks for you help guys !!!! =)
    Kind regards,
    Diego

    Hello Diego,
    It is technically correct SAP Business Workflow works with Positions but it is difficult to maintain the Org. objects in SRM and CRM applications. Because SRM and CRM have enhanced objects BP: Business Partner and CP: Central Person objects.
    You can check object relationship with infotype 1001 in PP02 transaction.
    Organization Unit - O 50000608
       -> Position - S 50000621
            -> Central Person - CS50006622
                -> Business Partner BP0000000111
                -> User USPURCHASER
    Regards,
    Masa

  • Find  job  descp  based on  position

    Hi ,
      In  HR  ,  I  want to find  Job  Desp  based on Position.
    Thanks,
    Asha

    Hi
    Check this FM
    HR_HCP_SEL_POSITION_OF_PERSON
    HR_HCP_GET_EMPL_FOR_POSITION
    HR_HCP_GET_JOB_FOR_POSITION
    HR_HCP_GET_ORGA_FOR_POSITION
    HR_HCP_GET_POSITION_FOR_EMPL

  • Remove the highlighted item

    Hello all,
    I got a problem hope you can help me. I have 2 lists in 2 scroll panes. I'd my application can handle: when user selects an item from list one (the item will be highlighted), the item in list 2 that user selected before must be deselected (remove the highlight from the list 2).
    How can implement it. I knew how to set selected item (JList.setSelectedIndex(5)) but I don't know how to de-select it.
    Thanks.

    I've never used it myself, but try clearSelection()

  • Remove role or user from position

    Hi all,
    we are on ECC 6.0; we are using indirect role assignment. We looking for a way to automate the removing of a user (US) or role (AG) from a position (S).
    eg. remove user 123456 from position 50000001 and user 654321 from position 50000002 in one shot.
    We have found the standard SAP program RHRHDC00 (RE_RHRHDC00 transaction) but is not designed for doing that.
    There's another standard program/function or... for solve this matters?
    Many thanks.
    Massimo

    We looking for a way to automate the removing of a user (US) or role (AG) from a position (S).
    There is a report called RHGRENZ2 which can be used to delimit specific OM infotypes (like IT1001- Relationships) specifying the end-date and Position ID (Object Type S and Object ID= Position) manually. In your case, I believe IT1001's Relationship A008 and B007 have to be delimited in order to remove a user (US) or role (AG) from a position (S) but this report cannot be run for specific relationship types of IT1001 (atleast I did never find an option to filter based on relationship types).
    You can try using report RHRHDL00 to delete IT1001 relationships from PP Database but you should consider the consequences of such deletions and restrict the selection based in infotypes and relationship types carefully.
    Alternatively, you can also build a LSMW script to automate the process of mass delimit/deletion of IT1001's relationship types using transaction PP02 (PP01 is not compatible to BDC/background processing)
    Thanks
    Sandipan

  • Split without delimiter based on position

    Hi,
    I am having a query i need to split the query based on the position i specify
    Say
    string is 123456789101112
    am having position as 1,1,2,5,4,2
    i need as
    1
    2
    34
    56789
    1011
    12
    I need to insert this in to my table
    create test table (col1 number(10),col2 number(10),col3 number(10),col4 number(10),col5 number(10),col6 number(10));
    col1,col2,col3,col4,col5,col6
    1,2,34,56789,1011,12
    Thanks

    i'm having some 80 columns in my table how to do for 80 columns Will data inserted into all 80 columns ?
    Will there any change in order of insertion i.e. suppose data will be in col1,col2,col10,col11,col15,col23,col45,col80,col14,col68,col5... ?
    How you will calculate the number of columns in which that number string is going to inserted ?
    If there are fix 80 columns then rather than writing block of code for 80 times, you can use varray type variable and then proceed ahead. Since, in the above code, I have not handled exception(s), so exception handling will be another part of code to make it smooth.
    Between, at the moment, I am not getting why there is error which is in the end :
    create type np_type is varray(80) of number
    create type cn_type is varray(80) of number;
    create type cxn_type is varray(80) of varchar2(100)
    I created TEST table by below pl/sql block :
    declare
    execstr varchar2(2000) :='create table test(';
    begin
    for i in 1..80 loop
    execstr:=execstr || 'col' || to_char(i) || ' number,';
    end loop;
    execstr:=substr(execstr,1,length(execstr)-1);
    execstr:=execstr || ')';
    dbms_output.put_line(execstr);
    execute immediate execstr;
    end;
    create or replace procedure myproc1
    strx in varchar2, delarray in np_type)
    as
    execstr varchar2(200);
    cn cn_type;
    cxn cxn_type;
    xpos number:=1;
    begin
    for i in 1..80 loop
    select Delimiterlength into cn(i) from sp_table where Splitid = delarray(i);
    select substr(strx,xpos,cn(i)) into cxn(i) from dual;
    execstr:='insert into test values(' || cxn(i) || ',';
    xpos:=length(cxn(i));
    end loop;
    execstr:=substr(execstr,1,length(execstr)-1);
    execstr:=execstr || ')';
    dbms_output.put_line(execstr);
    --execute immediate execstr;
    end;
    /SQL> declare
    2 v np_type:=np_type(4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4);
    3 begin
    4 dbms_output.put_line(v(80));
    5 --exec myproc1('11111111111111111111111111111111111111111111111111111111111111111111111111111111',v);
    6 end;
    7 /
    4
    PL/SQL procedure successfully completed.
    SQL>
    SQL> declare
    2 v np_type:=np_type(4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4);
    3 begin
    4 --dbms_output.put_line(v(80));
    5 exec myproc1('11111111111111111111111111111111111111111111111111111111111111111111111111111111',v);
    6 end;
    7 /
    exec myproc1('11111111111111111111111111111111111111111111111111111111111111111111111111111111',v);
    ERROR at line 5:
    ORA-06550: line 5, column 6:
    PLS-00103: Encountered the symbol "MYPROC1" when expecting one of the
    following:
    := . ( @ % ;
    The symbol ":=" was substituted for "MYPROC1" to continue.
    SQL>
    Try to remove this error. Here '1111...' is the string which is going to be entered and '44444...' is the Splitid of sp_table.
    Now, its your turn to help me.... :)
    Regards
    Girish Sharma

  • Report row highlight based on a page item

    Is there a way to highlight a report row based on the value of a page item?
    In my case I have a report where the application user requests data in a detail report using a column link in the master report. This loads an id number from my report into a page item (say :P8_ID for example). If this item is null, I want the report rows to all render normally (nothing is selected or the detail report has been closed). If there is an id in that field then I want the row containing the information about that item to highlight (its column link has been clicked selected it to bring up a detail report).
    At first glance, this looks similar to Vikas solution (Change the Report row color when clicked but I am trying to make the connection between what has already been done and where I need to be.

    After looking back, I discovered my value was being set after the report rendered. When I re-organized my calculations and the rest, it worked.

  • Can you remove all highlights at once instead of one at a time in a PDF?

    I have 12 PDF's that are 300-600 pages each where someone has highlighted large portions in gree, blue and yellow. I want to keep all yellow highlights and remove all green and blue. Is there a way to do this without having to delete the highlights from each individual page? Any assistance is greatly appreciated!
    Kevin

    Smitch1581 wrote:
    Can you please mark the question as answered so it will help others on the forum and give me 10pts :-)
    You going to buy a new car with 'em?

  • Default SC Plant Company code and Storage location Based on Position

    Hi All,
    We are on version SRM 7.02.
    We are using SAP ECC R/3 EHP7 based system as a back end FI and HR system.
    Org structure in SRM is replicated fromm HR system.
    We have case of concurrent employment in the HR org structure , which means one USER can be assigned to multiple Positions in an org structure.
    We have a user A , who is created in Two different org units say O1 , O2 occupying positions P1 and P2, belonging to company code C1 and C2.
    Whenever a SC is created a custom enhancement shows all the user positions to him and he has to choose one from the list of positions.
    Now based on the selected position(P1) , i have to default plant(PL1), storage location(SL1) and Company code(C1).
    Even after defaulting attributes based on the position, user gets an error "company code C1 is not valid for user"
    This error (Message class : /SAPSRM/CLL ; # 135) is thrown from method : /SAPSRM/CL_CH_WD_DODM_SC_I_BD /SAPSRM/IF_CLL_MAPPER~UPDATE
    after getting user's Company code using following method.
    /sapsrm/cl_pdo_shared_user=>/sapsrm/if_pdo_shared_user~get_company_code
    This gets Company code as C2 ; Based on Users Attributes and not based on User Position attributes.
    If i overwrite values fetched by this method in Implicit enhancement, then plant(PL1), storage location(SL1) are not getting fetched.
    Does anyone have any solution for this problem?
    Regards,
    Ashish Shah

    Hi MURUGESAN !
          Can you give me some information more in Special Procument Configure in plant 2000 like:
              -  Procurement type (maybe F)
              -  Special procurement (Maybe U)
              -  Plant (Maybe 1000).
              - Issuing plant (maybe 2000)
           We will check together.
           Regards,
          Tony

  • I need to remove blue highlighting around certain words in a pdf document.

    Someone tell me how.

    I'm not sure how to send a screenshot in this forum but it doesn't matter now. The problem was that I somehow removed the Form Fields without it removing the information in them as well as the blue highlight for selecting an answer to the individual questions.
    I ended up going into another copy of the application and using the Tools>Highlight Existing Fields operation and then going through and making sure the different form fields weren't locked and then deleting each one.
    Initially I used the left hand side Navigation Pane buttons to remove all embedded information which is what got rid of the form fields but not the info in those form fields, which included the blue highlight.
    Thank you for your help though.

  • User access based on positions

    Hi,
    Can you throw me some hints on handling following requirement on CRM 2007, User A plays himself 2 roles say e.g. Marketing and Sales professional, assigned to 2 different position (different business roles, configured with 2 different PFCG roles).  Marketing profession do not have edit access for master data in PFCG but it triggeres from Sales Professional PFCG role.
    How can I control techanical authorizations defined in PFCG based on BR selection:
    Thanks in advance.
    Bob

    Not sure if  undestand you properly, but if you mean that when user logs in in marketing bus.role, that he should get only privileges of pfcg role assigned to marketing bus.role and not also from sales pfcg role, then this is not possible.
    All pfcg roles are alwaysconsidered.
    Regards.

  • Billing based on Position Payer  (re-posted again)

    Hello,
    Let me explain my doubt.
    Our customer, the way of working, after creating sales order with documents flow, is modify de Payer at position level and later create again the Proforma billing, and the final billing.
    This crash with the standard way of billing, for example:
    Sales order A
    Header payer: n1
    10 Position payer: n1
    20 Position payer: n3
    30 Position payer: n1
    Sales order B
    Header payer: n2
    10 Position payer: n2
    20 Position payer: n3
    30 Position payer: n2
    Final billing by standard:
    Billing number 1: against payer n1 (OK)
    Billing number 2: against payer n2 (OK)
    The problem is against payer n3, system generate 2 differents billing documents instead of one per the same payer.
    Is it posible on VTFA- Billing based upon Order, item level 'Data VBRK/VBRP' , create a routine with a ZUKRI in order to billing by positions payers??
    Another solution, on VOPA,delete PY for header billing partner procedure and add PY to position billing partner procedure?
    I would be pleased if you can help us?
    I have created this 9XX rutine and now system is splitting by WE instead of RG:
    DATA: BEGIN OF ZUK,
    MODUL(3) VALUE '902',
    VBELN LIKE VBPA-VBELN,
    POSNR LIKE VBPA-POSNR,
    PARVW LIKE VBPA-PARVW,
    END OF ZUK.
    ZUK-VBELN = VBPA-VBELN.
    ZUK-POSNR = VBPA-POSNR.
    ZUK-PARVW = VBPA-PARVW.
    VBRK-ZUKRI = ZUK.
    Any idea
    Thanks in advance

    Hello,
    I have created this new routine and now system is splitting by WE instead of RG:
    DATA: BEGIN OF ZUK,
              MODUL(3) VALUE '902',
              VBELN LIKE VBPA-VBELN,
              POSNR LIKE VBPA-POSNR,
              PARVW LIKE VBPA-PARVW,
            END OF ZUK.
      ZUK-VBELN = VBPA-VBELN.
      ZUK-POSNR = VBPA-POSNR.
      ZUK-PARVW = VBPA-PARVW.
      VBRK-ZUKRI = ZUK.
    Any idea?

Maybe you are looking for

  • File Sharing Configuration

    Does anyone know where the file sharing settings in System Preferences are stored? I work with an iMac that has 4 standard accounts and 1 administrator account with File Vault, and somebody removed 2 of the standard account's public folders from the

  • Traffic Shaping for perticular traffic

    class-map match-any SYSLOG-CMAP match access-group name SYSLOG-ACL policy-map SYSLOG-PMAP class SYSLOG-CMAP   shape average 250000 interface GigabitEthernet0/1 ip address 1.1.1.1 255.255.255.252 ip flow ingress load-interval 30 duplex full speed 100

  • Macbook Pro won't eject cd completely

    When trying to eject a cd on my Macbook Pro I clearly hear the eject mechanism working as it should. But somehow the cd never comes out. Instead the drive acts as if a cd was just inserted and starts reading the disc. I've tried various commands in T

  • DOC_CHANGE_BADI not triggered for OLD SC-SAVE mode for EDIT- SAVE steps

    Hi Experts , We have SRM7.0 ( SP08) with ECC6 ( Ehp4) having Classic Scenario. In our business Price list ( Price in ECC Contract) will be always change  so, we have done small enhancement in BBP_DOC_CHANGE_BADI in method BBP_SC_CHANGE, to get latest

  • SQL Developer is free !

    Hello Everybody, Is SQL Developer tool is free or paid one? On Wikipedia I found that: "Oracle SQL Developer is an IDE for working with SQL in Oracle databases. Oracle Corporation provides this product free; it uses the Java Development Kit." Regards