Cannot remove attributes in HTMLDocument

With a JTextPane, HTMLDocument and two JButtons I can select a piece of text and format it (bold for example). Then I want to select it again and clear the format (non bold for example).
I do this with the code below.
The editor shows the text correctly. But when exporting the document to HTML (with HTMLEditorKit.write...), the text which I cleared of formattings is gone!
I only want to clear the formatting, not the text.
Any idea?
int start = editor.getSelectionStart();
int end = editor.getSelectionEnd();
Element element = htmlDocument.getCharacterElement(start);
AttributeSet attributeSet = element.getAttributes();
StyleSheet styleSheet = htmlDocument.getStyleSheet();
styleSheet.removeAttributes(attributeSet, element.getAttributes());
htmlDocument.setCharacterAttributes(start, end - start, attributeSet, true);

Hi,
in your code example you take the attributes of the element at the start of the current selection. Then you remove all elements to make the attribute set empty. The same can be achieved by a single line of code: AttributeSet set = new SimpleAttributeset(); creating an empty AttributeSet.
Then you apply the empty attribute set to the document with method setCharacterAttributes. Although you pass true in the 'replace' parameter of method setCharacterAttributes, this will not work because 'replace' only replaces explicit settings. I.e. when in the document there is a bold setting, the attribute set must have an attibute such as CSS.Attribute.FONT_WEIGHT set to 'normal' to overwrite the existing bold attribute. In your example, exisiting attributes are kept.
If you like to 'clear' any attributes from a range of text by passing an empty attribute set, you'd have to iterate through the affected elements within the selected text range and apply the empty attribute set explicitly to every element.
This can be done by subclassing HTMLDocument and adding a method as follows  /**
   * apply a set of attributes to a given document element
   * @param e  the element to apply attributes to
   * @param a  the set of attributes to apply
  public void addAttributes(Element e, AttributeSet a) {
    if ((e != null) && (a != null)) {
      try {
        writeLock();
        int start = e.getStartOffset();
        DefaultDocumentEvent changes = new DefaultDocumentEvent(start,
            e.getEndOffset() - start, DocumentEvent.EventType.CHANGE);
        AttributeSet sCopy = a.copyAttributes();
        MutableAttributeSet attr = (MutableAttributeSet) e.getAttributes();
        changes.addEdit(new AttributeUndoableEdit(e, sCopy, false));
        attr.addAttributes(a);
        changes.end();
        fireChangedUpdate(changes);
        fireUndoableEditUpdate(new UndoableEditEvent(this, changes));
      finally {
        writeUnlock();
  } When you iterate through every element in a given selection and call above method with an empty attribute set for each of the elements, all styles will be cleared and the range is reset to default settings. Ulrich

Similar Messages

  • ISE External RADIUS proxy remove attributes

    Hi all,
    I setup external RADIUS for authenticating external users on ISE 1.2  - I need to remove all attributes received from the external RADIUS but I cannot find how to do it.
    I checked the option
    On Access-Accept, continue to Authorization Policy
    in RADIUS server sequense Advanced Attribute settings 
    and in Authorization policy I setup proper attributes but I found the attributes from external RADIUS server are in the Access-Acceept response too.
    This is RADIUS debug from the switch:
    Apr 10 09:35:51 CEST: RADIUS: User-Name [1] 17 "xxxxxxxxxxxxx"
    Apr 10 09:35:51 CEST: RADIUS: Session-Timeout [27] 6 3600
    Apr 10 09:35:51 CEST: RADIUS: Termination-Action [29] 6 1
    Apr 10 09:35:51 CEST: RADIUS: Tunnel-Type [64] 6 00:VLAN [13]
    Apr 10 09:35:51 CEST: RADIUS: Tunnel-Type [64] 6 01:VLAN [13]
    Apr 10 09:35:51 CEST: RADIUS: Tunnel-Medium-Type [65] 6 00:ALL_802 [6]
    Apr 10 09:35:51 CEST: RADIUS: Tunnel-Medium-Type [65] 6 01:ALL_802 [6]
    Apr 10 09:35:51 CEST: RADIUS: EAP-Message [79] 6
    Apr 10 09:35:51 CEST: RADIUS: 03 08 00 04
    Apr 10 09:35:51 CEST: RADIUS: Message-Authenticato[80] 18
    Apr 10 09:35:51 CEST: RADIUS: BA 8C BC 8D 69 23 2B 7D 8A 70 20 D4 DE 96 0B E2 [ i#+}p ]
    Apr 10 09:35:51 CEST: RADIUS: Tunnel-Private-Group[81] 4 "17"
    Apr 10 09:35:51 CEST: RADIUS: Tunnel-Private-Group[81] 7 01:"v230"
    Apr 10 09:35:51 CEST: RADIUS: Vendor, Cisco [26] 22
    Apr 10 09:35:51 CEST: RADIUS: Cisco AVpair [1] 16 ""ssid=eduroam""
    Apr 10 09:35:51 CEST: RADIUS: Vendor, Cisco [26] 37
    Apr 10 09:35:51 CEST: RADIUS: Cisco AVpair [1] 31 "termination-action-modifier=1"
    Apr 10 09:35:51 CEST: RADIUS: Vendor, Microsoft [26] 58
    Apr 10 09:35:51 CEST: RADIUS: MS-MPPE-Send-Key [16] 52 *
    Apr 10 09:35:51 CEST: RADIUS: Vendor, Microsoft [26] 58
    Apr 10 09:35:51 CEST: RADIUS: MS-MPPE-Recv-Key [17] 52 *
    As you can see a lot of attributes are twice in the response. I need only "v230" set as VLAN ID
    I looked for removing the attributes but "Modify attribute" settings (iether "in the request" or "before access-apccept") offer only subset of RADIUS attributes - I need to remove attribute 81 - Tunnel Network Private Group - but it is not offered there.
    Can somebody advice me, how to (idealy) remove all atrributes from external RADIUS or at least remove set of attributes at minimum with attribute 81?
    Thank you for any help

    Thank you,
    I duplicated the Dot1x Authentication Rule, and changed allowed protocols to "RADIUS Server Sequence : MySequence"
    In the RADIUS Server Sequence under the advanced tab I have it set to "Continue to Authorization Policy'.
    Which Authorization rule would match?
    Network Access:RADIUS Server Sequence EQUAL MySequence
    OR
    Network Access:UseCase EQUALS Proxy
    OR
    None of the above?
    Thanks

  • Getting error when opening project created in FC/FB CS5.5  - cannot resolve attribute 'clear'

    I have a project I created earlier this year in panini/burrito, but when I upgraded to CS5.5 I get 18 of the the following errors:
    "Cannot resolve attribute 'clear' for component type flashx.textLayout.elements.SpanElement. Main.mxml /imagine/src line 406 Flex Problem"
    I'm not very kbowleadgeable in flaex, so I'm trying to muddle through this.
    Here's the active site by the way.
    www.imaginenewmedia.com
    It seems to be related to lines of code which lay out text on the "packages" page.
    thanks!

    fixed! removed offending parameters from code.

  • Downloaded Firefox 4--computer asks over and over to restart, Firefox will not load, cannot remove it!!

    I received an update message after my system had installed the newest Firefox 3. something, approximately 4 days ago. (Today is 3/22, so about 3/17--18) The newest update , when started, took me to the Mozilla homepage, where It was suggested I download and comment on the new Firefox 4---I do not normally do this, but am so impressed with Firefox versus most others, that I did, now, I cannot open Firefox at all, the older version, 3. something, is not in my system, only 4, but my system/PC upon trying to open the new Firefox, prompts me over and over to restart the system, (which I have done 3 times) I figured I would then simply remove it, (Firefox 4) and either try it again, or re-install the newest 3. something---I cannot remove it, even using my anti-virus program to do so, it simply prompts over and over to restart, wether I try to open, remove, or access it in any way---I do not wish to use system restore, but that seems my only option, please help!!!

    I had the same problem and the solution is quite simple:
    - delete all data that has to do with Firefox and Mozilla
    - Reinstall the new version Firefox 4
    You have to make sure that everything is deleted and well yes you will lose your profile data but at least it works again without any problem.

  • How do I remove an old phone number from my macbook imessage. My apple ID does not show the number anymore but I cannot remove it from the imessage accounts. Its driving me mad !

    Can someone please help me to remove an iphone telephone number from my imessage application. I no longer have a phone which I registered on my apple ID as a second phone. I have been on my apple ID and it does not seem to be there but cannot remove it from imessage, which still has it as an option to connect to. I am concerned that someone else who inherite this old phone will see my messages if I accidentally enable it again. I have read and re-read various postings and tried all options given but no luck, the **** thing stays there.....

    Hey Chappers64!
    Here is an article that will help you with this issue:
    iOS: Deactivating iMessage
    http://support.apple.com/kb/ts5185
    If you have already tried these steps, you will want to utilize the information at the end of the article:
    If you can't deactivate iMessage after you perform the steps above or you can't access the iPhone, please contact Apple Support.
    Thanks for coming to the Apple Support Communities!
    Cheers,
    Braden

  • ITunes on my phone is no longer playing some songs, even those I have purchased with my phone.  They will play fine on my pc itunes.  I also cannot remove the audio books that are on my phone and add others and the audio books on my phone will not play.

    I am unable to play new songs purchased on my phone and some old songs on my ipod/iphone.  They all work fine in iTunes on my computer.  I also cannot remove the audiobooks from my phone when I sync even though I have unchecked said books, and I cannot play them either.

    C Mawle wrote:
    Thanks.  I have followed all the instructions as recommended and nothing has worked so it looks like the restore/update may have been interrupted - would loss of internet connection do this?
    Yes it would, possibly even brick it.
    Have successfully connected my ipod nano with iTunes so looks like the device driver is working.
    Can I use my ipod nano USB connector to check?
    It is not much help to you, since the device that you need still not recognized.
    Anyway looks like I may have to swallow the loss of data.  Have set-up a call for tomorrow with Apple support so will wait until after this before doing the factory restore!
    Good luck, but if you expect miracle from that call good luck again.

  • Error message: cannot remove older versions of apple software update

    I recently got a 30 gb ipod, and i cant install itunes 7. I originally tried installing it at first, and it said cannot remove older applications of Apple Software Update. So i installed itunes 4 to put music on my ipod. Then i tried again to install itunes 7 and i keep getting the same error message. Anyone else having this problem? Can anyone give me some suggestions please?

    I would first try and remove both iTunes and Quicktime prior to doing the install of iTunes. The following link will show you how to remove both programs. Make sure you do Step 16 as it is usually Quicktime that causes problems with the upgrade.
    http://docs.info.apple.com/article.html?artnum=93698
    If it will not let you remove the programs, you can try using the Windows Installer Cleanup Utility. The download is about 1/4 of the way down the page. Good luck.
    http://support.microsoft.com/default.aspx?scid=kb;en-us;290301

  • When I plug my ipod in I am able to add song to it but the tab that says "on this ipod" no longer shows up so I cannot remove things from my ipod or anything like that. How do I change this weird setting?

    When I plug my ipod in I am able to add song to it but the tab that says "on this ipod" no longer shows up so I cannot remove things from my ipod or anything like that. How do I change this weird setting? On other computers this shows up fine so it is clearly a problem with itunes and not my ipod.

  • ITunes will not install because it cannot remove an earlier version of Bonjour...HELP!!!!

    When I try to install iTunes 10 it cuts in about 3/4 of the way saying that "Cannot remove and earlier version of Bonjour"....PLEASE HELP!!!!!

    (1) Download the Windows Installer CleanUp utility installer file (msicuu2.exe) from the following Major Geeks page (use one of the links under the thingy on the Major Geeks page):
    http://majorgeeks.com/download.php?det=4459
    (2) Doubleclick the msicuu2.exe file and follow the prompts to install the Windows Installer CleanUp utility. (If you're on a Windows Vista or Windows 7 system and you get a Code 800A0046 error message when doubleclicking the msicuu2.exe file, try instead right-clicking on the msicuu2.exe file and selecting "Run as administrator".)
    (3) In your Start menu click All Programs and then click Windows Install Clean Up. The Windows Installer CleanUp utility window appears, listing software that is currently installed on your computer.
    (4) In the list of programs that appears in CleanUp, select any Bonjour entries and click "Remove", as per the following screenshot:
    (5) Quit out of CleanUp, restart the PC and try another install. Does it go through properly this time?

  • I have an Iphone 5s with an account icloud that isn't an iCloud id, why? I cannot remove and the mail that names id doesn't exist anymore; what can I do?

    I have an Iphone 5s with an account icloud that isn't an iCloud id, why? I cannot remove and the mail that names id doesn't exist anymore; what can I do?

    Welcome to the Apple community.
    If you are unable to remember your password, security questions, don’t have access to your rescue address or are unable to reset your password for whatever reason, your only option is to contact Apple ID Support, upon speaking to an operator you should explain that your problem is related to your Apple ID, this way you will not be charged for assistance, even if you don’t have an AppleCare plan.
    You will need to show patience with the procedure and be prepared to demonstrate without question that the account belongs to you. Don’t expect access to be restored immediately and if you aren’t the owner of the Apple ID registered to the device the account won’t be reset.
    This is answer is provided from my own database of boilerplate responses and the content was last reviewed and/or tested on: 2014/12/18

  • How do I remove the Certified Toolbar Search toolar??-- MALWARE -- tried everything I know -- cannot remove UIGGHH!!!

    I have tried ALL the malware removal tools I know of and still cannot remove this!

    hello, please install the search reset addon - it will revert the most common customziations those adware programs do in firefox back to the default: https://addons.mozilla.org/firefox/addon/searchreset/
    if your settings don't stick after a restart of the browser also go to firefox > help > troubleshooting information > profile folder - "show folder", then a new window will open up. in this window look out for a file named '''user.js''' (it might be used to overwrite your custom settings). in case it is present , delete or rename this file and restart firefox afterwards.
    [[Remove a toolbar that has taken over your Firefox search or home page]]
    [[How to fix preferences that won't save]]

  • I cannot remove the dialog box from my ipad. It says 'not enough storage' I click on settings and close, but still there. I need help. thx

    I cannot remove the dialog box from my ipad. it says 'not enough storage'. I click on settings and close but still there. How can i remove this message? Thnx

    Try this.
    Reboot the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider if it appears on the screen - let go of the buttons. Let the iPad start up.

  • I have just downloaded itunes. I cannot install QT as an older version is in place. Cannot remove the older version using CP. Any ideas?

    I have just downloaded itunes. I cannot install QT as an older version is in place. Cannot remove the older version using CP. Any ideas?

    Many thanks.
    Unfortunately, this sort of trouble has gotten more complicated to deal with ever since Microsoft pulled the Windows Installer CleanUp utility from their Download Center on June 25. First we have to find a copy of the utility.
    Let's try Googling. (Best not to use Bing, I think.) Look for a working download site for at least version 3.0 of the Windows Installer CleanUp utility. (The results from mydigitallife and Major Geeks are worth checking.)
    After downloading the utility installer file (msicuu2.exe), scan the file for malware, just in case. (I use the free version of Malwarebytes AntiMalware to do single-file scans for that.)
    If the file is clean, to install the utility, doubleclick the msicuu2.exe file you've downloaded.
    Now run the utility ("Start > All Programs > Windows Install Clean Up"). In the list of programs that appears in CleanUp, select any QuickTime entries and click "Remove".
    Quit out of CleanUp. Restart the PC, and try another iTunes install. Does it go through properly this time?
    Message was edited by: b noir

  • HT1925 cannot remove bonjour and itunes wont re-install because of it

    cannot remove bonjour program from old itunes when trying to update itunes by uninstalling and re-installing itunes 10.7

    (1) Download the Windows Installer CleanUp utility installer file (msicuu2.exe) from the following Major Geeks page (use one of the links under the "DOWNLOAD LOCATIONS" thingy on the Major Geeks page):
    http://majorgeeks.com/download.php?det=4459
    (2) Doubleclick the msicuu2.exe file and follow the prompts to install the Windows Installer CleanUp utility. (If you're on a Windows Vista or Windows 7 system and you get a Code 800A0046 error message when doubleclicking the msicuu2.exe file, try instead right-clicking on the msicuu2.exe file and selecting "Run as administrator".)
    (3) In your Start menu click All Programs and then click Windows Install Clean Up. The Windows Installer CleanUp utility window appears, listing software that is currently installed on your computer.
    (4) In the list of programs that appears in CleanUp, select any Bonjour entries and click "Remove", as per the following screenshot:
    (5) Quit out of CleanUp, restart the PC and try another iTunes install. Does it go through properly this time?

  • Removing attributes from node

    Hi,
    Im creating a node and its attributes dynamically and binding it to a table to show a table dynamically. The problem is that when i load a new item, i have to rebuild the node and table because it might have different columns. The node allways has 3 fixed columns (id, name, description) so first i have to remove all of the attributes except the id, name and description. Same for the table columns. Can anyone tell me how to remove attributes from a node or how to differently solve my problem? All i see is how to remove an element but is a data right, not the model?
    Much thanks,
    Hugo Hendriks

    Hi,
    I had a similar situation, where 2 table columns were always present, and the name and type of other columns were only available runtime.
    I simply deleted all data (invalidate()) and recreated the context from scratch after each model execution that impacts the table structure.
    Otherwise, use the API to find the right methods for deleting Nodes and Elements.
    https://media.sdn.sap.com/javadocs/NW04/SPS15/wd/index.html
    Good luck,
    Roelof

Maybe you are looking for

  • Error in CF Administrator After Update to 9.0.1

    I'm attaching an image of the error I get when I click the first "Settings" Link under "Server Settings" menu.  I did some searching but I couldn't find anyone that was having a similar problem. Any help would be appriciated. Thanks, Paul

  • Using the iMac 27" display as a...Display

    Hey, I'm new to the forum, and I don't own a Mac (YET!!) but I'm really looking to treat myself. I was wondering if there was a way of hooking up a blu ray or other HDMI device to the iMac screen? It would make buying one a lot more attractive, as I

  • How Can I Get Rid Of This?

    I've just downloaded a new toolbar and on my browser it doesn't show the top part of the page and there's a big line on the bottom and parts of the toolbar aren't showing up. It looks just like this: http://i.imgur.com/uRjCb6p.png Also whenever i scr

  • Problems with authenticated smtp on Mac mail 2

    I do support for a small ISP and we are seeing problems with Mac Mail authenticating to the smtp server. The settings that should work are: outgoing server: asmtp.gorge.net Username: full email address Outgoing server port: 2525 or 587 We typically t

  • What is the Exceptions in function module

    Hi, wt is the exceptions in function module? can anyone tell me? Thanks swathi