Changing HTML attributes

Hi,
My application can display HTML pages in a JTextPane. It can highlight parts of the text to make them stand out. But this is a problem when the HTML document has the same color that is used for highlighting the text. It makes the text look invisible!
So I would like to be able to change the background color to white, no matter what is in the original HTML document. (Later, I will also be wanting to change the font color to black, and maybe remove/change some other attributes, but one thing at a time!)
A StyledDocument is created with this code: EditorKit ek = new HTMLEditorKit();
StyledDocument myDoc = (StyledDocument)ek.createDefaultDocument(); The HTML from the file is then read into myDoc with the "Read" method of the EditorKit. This StyledDocument will be used in another class which displays it on the JTextPane. But I want to change it BEFORE it goes on the JTextPane.
Because the JTextPane accesses myDoc, I made a temporary StyledDocument called tempDoc to read the HTML into, then **hopefully** make my changes to, so that the very last line can be myDoc = tempDoc to make sure that myDoc only gets the very final changes.
I use a Javax.Swing.Text.ElementIterator over the StyledDocument to get all of the elements and see if it's the body element using the Element.getName() method. This part works, because I have lots of println's in to see what is happening.
I then use a SimpleAttributeSet and construct it using (bodyElement.getAttributes()). Then I tell it this: SimpleAttributeSet sas = new SimpleAttributeSet(bodyElement.getAttributes());
sas.removeAttribute(sas.getAttribute(HTML.Attribute.BGCOLOR));
sas.addAttribute(HTML.Attribute.BGCOLOR, "white");
tempDoc.setCharacterAttributes(0, tempDoc.getLength(), sas, true); For the last line in particular, I feel like I've tried everytthing! Many different combinations.
What I notice happening is that often the HTML document in the JTextPane displays the original document. Or else, all of the Elements, including content, are replaced with the <body bgcolor=white"> tag. (I make the EditorKit write out the resulting HTML file to see what's going on!). In the JTextPane, the original bgcolor remains, even if the content disappears. In the Browser, the bgcolor is the right color (with the content still missing.)
Please do not tell me to edit the HTML files themselves as they are the client's, and it's a nicer solution for the program to handle them rather than tell the people to manually edit all of the files. Plus, the files are machine-generated, so there might not be anyone who even knows HTML!
I have also tried using StyleConstants to change the colors, but this only changes the colors right behind the text. So the bgcolor is still displayed, but it looks like someone has run a white highlighter over the text. Quite ugly!
I hope I have explained this well. The code is quite complicated (and messed up right now because I have been playing with it all day) so I haven't posted it. If you have any questions to clarify it, please ask!
Thanks in advance to anyone who takes a look and attempts to help. (There are Dukes cuz everyone seems to like them, even though I don't really know what they do. A ranking system?)

Ok, I deleted all of my changes and started again. This time, I set the Paragraph attributes instead of Character Attributes (I read the API properly and it said that set Character Attributes changes all of the content element attributes). That would explain why all of the text disappeared, lol! It doesn't explain why the original document was still being displayed in the JTextPane, but when I set Paragraph attributes, the document with the correct color background appears.
There are still a couple of funny things happening. Cuz I'm lazy I'll post the resulting and original HTML files here:
ORIGINAL:
<html>
<head>
<title>A Test Document</title>
</head>
<body bgcolor=red>
A red document
<p>
New paragraph
</body>
</html>
RESULTING:
<html>
<head>
<body bgcolor="white">
<title>A Test Document </title>
</body>
</head>
<body bgcolor="red">
<body bgcolor="white">
A red document
</body>
<body bgcolor="white">
New paragraph
</body>
</body>
</html>
It would be nice if only the <body bgcolor=red> tag would be replaced with <body bgcolor="white"> instead of getting inserted everywhere (even in the HEAD tag). I tried setting the Paragraph attributes to bodyElement.getStartOffset and getEndOffset() but it didn't work either.

Similar Messages

  • Remove an html attribute in a html document

    Hi...
    Can someone give me a piece of code describing how I can remove a html attribute for the text under the current caret position or selection?
    If I have a <font class="..."> tag, I want to delete the class attribute, but maybe still want to have the font tag because it can contain some other attributes, face, size etc.
    I can get the current attribute with the AttributeSet attr = getCharacterElement().getAttributes().
    To be able to delete an attribute in the AttributeSet, I have to put it in a SimpleAttributeSet object?
    If I do that and delete the class attribute with the removeAttribute method and then put the changed AttributeSet back with setCharacterAttributes and setting the replace parameter to true, the selected text is removed...
    Any solutions?

    I don't know exact answer. It's only my suggestions!
    Foreground color in HTMLDocument differ from DefaultStyledDocument
    in the HTMLDocument color is specified with appropriate TAGs (like <FONT>).
    when you change source html text the document tree structure is changed according to html content and your settings are disappeared.
    Try to change source html text.
    Could you tell me what do you want to achieve?
    may be i can suggest a solution...
    i tryed to create an example... but it's unstable.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    import javax.swing.event.*;
    import javax.swing.tree.*;
    import java.util.*;
    class Test extends JFrame {
    JEditorPane edit;
    public Test(){
    super("Test");
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().setLayout(new BorderLayout());
    edit = new JEditorPane();
    edit.setEditorKit(new HTMLEditorKit());
    //edit.setDocument(new MyHTMLDocument());
    edit.setEditable(true);
    edit.setText("<HTML><FONT CLASS='c1' COLOR=RED><B>red text</B></FONT></HTML>");
    JScrollPane scroll=new JScrollPane(edit);
    getContentPane().add(scroll,BorderLayout.CENTER);
    JTree tree=new JTree((TreeNode)edit.getDocument().getDefaultRootElement());
    getContentPane().add(tree,BorderLayout.WEST);
    JButton btn=new JButton("test");
    ActionListener lst=new ActionListener() {
    public void actionPerformed(ActionEvent e){
    HTMLDocument html_doc=(HTMLDocument)edit.getDocument();
    Element el=html_doc.getCharacterElement(1);
    MutableAttributeSet newAttr=new SimpleAttributeSet();
    StyleConstants.setForeground(newAttr,Color.blue);
    html_doc.setCharacterAttributes(1,3,newAttr,false);
    try {
    html_doc.insertString(0,"",null); //this call do nothing but notifies that document is changed
    catch (Exception ex) {
    ex.printStackTrace();
    Element font=el.getParentElement();
    MutableAttributeSet attr=(MutableAttributeSet)el.getAttributes();
    btn.addActionListener(lst);
    getContentPane().add(btn,BorderLayout.SOUTH);
    setSize(300,300);
    setVisible(true);
    public static void main(String a[]) {
    new Test();
    and don't worry about dukes:-))
    i just want to help you.
    best regards
    Stas

  • How to change html style titles of a JTabbedPne at run time??

    hi,
    how to change html style titles of a JTabbedPne at run time??
    setTitleAt is not working...

    You can't change the canvas at runtime. But you can put the scrollbar on a stacked canvas and then show or hide that stacked canvas on different canvases.

  • How to change the attribute name for a relation

    When the Data Modeler engineers a logical model into a relational model it create table columns for the relations. The names of the generated columns are listed in the attributes list in the properties dialog of the relation. The actual name of the attribute gets calculated by the attribute name of the entity which is part of the relation. This is okay, if there is only one relation between two entities. But when there are two relations between two entities the second attribute gets a stupid number suffix. This makes it impossible to give the attribute a useful semantic meaning.
    When I engineer the model into a relational model I can change the column name in the relational model. Changing the column name in the relational model is not perfect but it would be okay for me, if it would not be overwritten during the next engineering run.
    So I have two questions:
    How can I change the attribute name in the attributes section of the properties dialog of a relation? See here for screen shot:
    http://public.ceving.de/2012050300/relationattribute.png
    And if it is not possible:
    How can I preserve any changes on column names in the relational model during a re-engineering run?
    Edited by: 931739 on 03.05.2012 08:07

    Hi,
    I've logged an Enhancement request on this.
    I don't believe it's possible to change it from the Entity or Relationship dialog, as it's not updatable in these dialogs.
    What you can do is change it in the Relational Model, and then reverse engineer the change back to the Logical Model.
    David

  • How to change report attributes like heading, sort etc programmatically

    Some of the columns from a classic reports using pl/sql as region source should be sortable. Is it possible to change this attribute (sort = yes) using JavaScript or APEX API?
    David
    Edited by: david on Sep 6, 2011 11:56 PM

    There is something I don't understand here. Why do you need to point at the sxd? What is changing? Like I mentioned before. If the contents of the xsd change, all the report will do is - at best - drop the changed fields so you will be missing data. Perhaps some of the following will help;
    [Crystal Reports Guide To ADO.NET|http://www.sdn.sap.com/irj/boc/go/portal/prtroot/docs/library/uuid/401c4455-a31d-2b10-ae96-fa57af5aec20?quicklink=index&overridelayout=true]
    [Crystal Reports For Visual Studio .NET Reporting Off ADO.NET Datasets|http://www.sdn.sap.com/irj/boc/go/portal/prtroot/docs/library/uuid/2091d0c3-da1d-2b10-22be-a3426b183f75?quicklink=index&overridelayout=true]
    [Crystal Reports For Visual Studio 2005 Walkthroughs|http://www.sdn.sap.com/irj/boc/go/portal/prtroot/docs/library/uuid/2081b4d9-6864-2b10-f49d-918baefc7a23?quicklink=index&overridelayout=true] (page 332 on).
    Ludek

  • How to get the "link" HTML.attribute

    What are the HTML.attribute that could contain a link ?
    The most common are
    HREF and
    SRC
    but there are too : ACTION, BGCOLOR ...
    and attribute that doesn't contain links like width ...
    Is there anyway to know the attributes that can contain links, or if someone knows the full list.
    Thanks

    Hmm.. got your meaning.. maybe its kind of weird to say but how about trying to see which similiar html tags can = "url" ? If the similiar html tags can, sure can the attribute.
    Just my cents..

  • How to change the attribut of Form in Review Form in ISR

    Hi,
    We have to change the attributes of text fields of form ( e.g disabling the text field ) once user hits the Review Form button on MSS page
    Please let me know how to do it .
    Thanks
    Manish

    Hi Manish,
    You may write the Formcalc scripting for the respective field.
    //Check ISR control parameters for read/write access
    if($record.CONTROL_PARAM.ISR_MODE == "DISPLAY" |
       $record.CONTROL_PARAM.ISR_FORM_VIEW =="ISR_APPROVE" | <b>$record.CONTROL_PARAM.ISR_REVIEW == "true" )</b>
    then
         this.access = "readOnly"
    else
         this.access = ""
    endif
    Hope this helps.
    Thanks and Regards,
    Anto.

  • How to change the attributes of GUI CONTROLS in my own program.

    hi all,
    i just want to change the attributes of GUI CONTROLS in my own program.
    for example `
    How to set an ICON on my GUI BUTTON in the program?
    so what's the mapping between CONTROL in the SCREEN PAINTER and variable in the program?

    Hi Chao Liu,
    Ya , u first find out the PF-STATUS of the screen and goto that status and now u can modify the ICON u want .
    Finding the GUI status of the screen
    Goto that  TRANSACTION CODE or SCREEN
    On the Standard Menu bar Goto ( Menu path) System --> Status
    Now u get a pop-up System :status in that in SAP Data block u can find GUI Status. Now Double Click on that Status. It takes u to the Status of that screen.
    Now click on the Display --> Change Button on the application tool bar.
    If it is a standard GUI-status then it asks for the ACCESS KEY.
    if it is a custom defined GUI Status  then u can change the status .
    reward if helpful
    raam

  • How to change the  attribute of screen field to drop down list dynamically

    Hi All,
      Col X                   Col Y
      A                        input field
      B                       drop down list
    This is a tabular disply where the Screen field attribute for Col y  is NO DROP DOWN BOX.
    My requirement is to change the attribute of COl Y to DROP DOWN list depending on the value of
      COL X  dynamically.

    Dear Ajay,
    Actually this requirement is to enhance the standard screen for Tcode :EHSVU21.
    So depending on the 1st Column(Test no)  value ,i have to change the 3rd Column(Low.norm.result)
    property either to DROP Down or not.
    So in the PBO only the changes to be made and there is no field in SCREEN internal table for changing the attribute to DROP down. I checked SCREEN internal table where the field VALUE_HELP and REQUEST is useful but not  suitable for my case.
    Any solution available?

  • Question about HTML attributes

    I am parsing HTML code and need some help. Maybe it's because
    I don't understand HTML code or something.
    Anyways, I'm trying to get the content of an HTML element. Given the
    following Java code:
         // Iterate through the elements of the HTML document.
         ElementIterator it = new ElementIterator(doc);
         javax.swing.text.Element elem;
         while ((elem = it.next()) != null) {
              SimpleAttributeSet s = (SimpleAttributeSet)elem.getAttributes().getAttribute(HTML.Tag.A);
              if (s != null) {
              System.out.println(s.toString());
              System.out.println(s.getAttribute(HTML.Attribute.HREF));
              System.out.println("element: " + elem.toString());
              if (elem.getName().equals("tr")) {
              System.out.print("found TR: ");
              Enumeration e = elem.getAttributes().getAttributeNames();
              while (e.hasMoreElements())
                   System.out.print(e.nextElement().toString() + " ");
              System.out.println();
    I can't figure out how to parse the content from table data.
    Here is my HTML code:
    <TR VALIGN="top">
    <TD ALIGN="left" COLSPAN="2">
    <FONT FACE="Monospace,Courier">KDEN 191753Z 10007KT 050V150 10SM FEW090 SCT120 SCT200 29/M01 A3004 RMK AO2
    SLP087 VIRGA DSNT S-NW TCU DSNT SW T02891011 10294 20128 58007</FONT><BR>
    <FONT FACE="Monospace,Courier">KDEN 191653Z VRB05KT 10SM FEW090 SCT120 SCT200 28/00 A3006 RMK AO2 SLP095 VIRGA
    DSNT SW-NW T02830000</FONT><BR>
    <BR>
    </TD>
    </TR>
    The code picks out the HTML attribute "valign" for the TR element. But,
    how do I get to the actual content.
    What I would like is to get the string that begins with KDEN.
    Any comments would be helpful.
    Thanks.
    -brad w.

    I was able to make this work.
    What I did was the following:
    <code>
         // Parse the HTML.
         kit.read(rd, doc, 0);
         // Iterate through the elements of the HTML document.
         ElementIterator it = new ElementIterator(doc);
         javax.swing.text.Element elem;
         while ((elem = it.next()) != null) {          
    //          System.out.println("element: " + elem.toString());
              if (elem.getName().equals("content")) {
              start = elem.getStartOffset();
              end = elem.getEndOffset();
              // System.out.println("found content: beg_offset: " + start + "end_offset: " + end);
              if ((end-start) < 4)
                   continue;
              try {
                   loc = doc.getText(start, 4);
              } catch (BadLocationException ex) { continue; }
              if (loc.startsWith("KDEN"))
                   System.out.println(doc.getText(start, end - start));
    </code>
    I need to use the start and end position of the element to get
    the text from the Document.
    -brad w.

  • .change IUCONFIG attribute value in an event-handler of IUICCON (move in)

    Hi there,
    I have been searching for over a week now both on SDN and using the debugger, hopefully this brings more luck.
    On the web-client there is this new contracts page with 3 tabs.
    On the first tab you can choose a product, select a contract and then click Configuration.
    There you can change parameters. (this is View IUCONFIG/ConfigTree) with contextnode ISUORDERITEMCONFIG.
    In this case it is not wanted that this configuration page needs to be opened.
    So I need to change the value of 1 of these attributes (always the same attribute) automatically when switching to the 2nd tab, or when clicking the save button on the last tab. Or any event on the 2nd or 3rd tab are okay. As long as they are sure to be executed in the process.
    I would prefer changing the attribute from within IUICCON/ProcessSaveButtonBar>EH_ONBT_SAVE_PROCESS
    or IUICCON/ProcessBar>EH_ONNAVTOACCOUNTDATA
    I just don't have a clue how to automatically set one value of these configuration attributes.
    Can anybody provide a solution or a workaround?
    Is there any way to change the parameters without ever going to the configuration page in the browser?
    Thanks in advance for your ideas
    Could this thread be moved to CRM webclient?

    Solved, the solution can be supplied in trade for the right amount of money
    (okay is was CRM_ISU_CONT_CHANGE_OW)

  • How to change the attributes of screen fields dynamically

    <b></b>
    well i have created a table by name empmaster_data with following fields.
    *emp_id.
    *emp_fname.
    *emp_lname
    *dob.
    *doj.
    *dept.
    *desig.
    now using a single screen i want to create,change and display the information.even i am using save and exit button.
    now i want to change the attributes of screen fields dynamically like active,input,output,invisible.

    Hi,
    Have Different Radio Buttons for the purposes what you have and use AT Selection Screen Output, Under the event Use loop at screen and with continue with your requirement.
    Hope This Info Helps YOU.
    <i>Reward Points If It Helps YOU.</i>
    Regards,
    Raghav

  • How do I change text attributes within one text box in Motion 3?

    I am trying to change text attributes within one text box in Motion 3, but am only able to change the font/size for the entire box. Is there a way to change the attributes to individual lines of text within a text box without creating an entirely new one or using the "Lower Third" text effect?
    How do I create (two different) multiple colors, fonts, bold, italic, underline in one text box within Final Cut Studio Motion (FCP, FCS)

    Thank you! You saved me hours of tinkering around with multiple text boxes. It seemed like it should be something pretty elementary. It didn't help that I am not familiar with proper terminology, so thank you for defining glyph.
    Cheers,
    Owfownugi

  • CR Reports 2008: Space Between HTML Attribute and Value Causes Attribute To Be Ignored

    I have a field in a report with its Text interpretation set to "HTML Text".  When content is rendered in that field that was sourced from a Microsoft Word document, some of the attributes seem to be ignored by Crystal. 
    For example, I have observed with "style" attributes that if there is a space between the attribute and the value, e.g. "FONT-FAMILY: SimSun" then Crystal will not render the Asian characters, replacing them with squares.  However, if I manually remove the space so that the attribute appears as "FONT-FAMILY:SimSun", then the characters properly render as expected.  I have observed the same issue with at least one other attribute as well, "FONT-SIZE".
    This html does render properly in various browsers, so it seems to be an issue with Crystal Reports.  Can you provide me with information about this and if there is a fix for it in subsequent versions.  The version I tested with is 2008 - 12.5.0.1190.
    Thanks for any assistance that you can provide.

    hi Ethan,
    here are the list of supported html tags in text interpretation...font family is indeed a supported tag.
    does the html appear properly in the designer?...you mentioned various browsers and am wondering if you mean the crystal web viewers?
    if the issue is in your cr designer, you may wish to patch it to the latest level.
    also, ensure that you do not have any unsupported tags in your html that may be causing an issue.
    -jamie
    html
    body
    div (causes a paragraph break)
    tr (causes only a paragraph break; does not preserve column structure of a table)
    span
    font
    p (causes a paragraph break)
    br (causes a paragraph break)
    h1 (causes a paragraph break, makes the font bold & twice default size)
    h2 (causes a paragraph break, makes the font bold & 1.5 times default size)
    h3 (causes a paragraph break, makes the font bold & 9/8 default size)
    h4 (causes a paragraph break, makes the font bold)
    h5 (causes a paragraph break, makes the font bold & 5/6 default size)
    h6 (causes a paragraph break, makes the font bold & 5/8 default size)
    center
    big (increases font size by 2 points)
    small (decreases font size by 2 points if it's 8 points or larger)
    b
    i
    s
    strike
    u
    The supported HTML attributes are:
    align
    face
    size
    color
    style
    font-family
    font-size
    font-style
    font-weight
    In Crystal Reports 2008 Service Pack 2 and above, the following additional HTML tags and attributes have been added to the supported list:
    The supported HTML tags are:
    ul  ( bulleted list )
    ol  ( ordered list )
    li   ( tag defining a list item used for both list type: ul and ol. )
    Important Note: The bullet will not show up as a regular size bullet, but as a small dot.
    The supported HTML attributes are:
    strong ( bold )

  • How to change general attribute of text element

    hi
    who now how to change general attribute of text element on screen dinamically? I wish to change text value dinamically for example.

    Hi Denis,
    I am not too sure on what you want.
    If you require that the text value be different based on some conditions you can declare as many text elements as conditions and call the relevant text element.
    But I dont think that you can assign dynamic texts to a single text element.
    Regards,
    Saurabh

Maybe you are looking for

  • How to create a custom file dialog box/vi (win)??

    Hello, I'd like to create a custom file dialog box to handle the reading of my tdms files. Basicly I want to extend the existing file select dialog box with a graphical preview of the data in the selected file. I know I can create all the logic for f

  • Can no longer see my Airport Extream

    Have successfully connected to the net, both through wlan and lan. Have also connected a server to Airpor Extream. When I now wanted to install a printer to Airport Extream, suddenly the Aiport Utility wont find neither the Aiport Extream, nore the 2

  • Which computer should I get?

    Hello, I'm setting up to make my first independent movie, and I'm planning on using an Apple instead of a PC. So, my question is -- because I'm new to the Apple World -- should I go with a MacBook Pro or a G5? Also, I'm using the Panasonic HVX-200. T

  • Import purchase-EXIT /BADI

    Dear All, Scenario: In import PO you are well aware that CVD condition types are used...now against these condition types we can maintain Custom vendor code (directly in PO or can flow from any condition record)...now we have four custom vendor codes

  • Is the iPad 2 covered by an International Warrenty Re: light leakage

    My brother in-law returned from the USA at the weekend from business and bought me an iPad 2 back from the Las Vegas Apple Store, as I had asked him to. I'm experiencing the light leakage along with the video camera shooting weird colours. My questio