Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HTMLEditorKit and CSS

843804Dec 18 2004 — edited Feb 28 2005
I'm having problems using CSS with HTMLEditorKit . Here it is a small example:
package com.textpane.gui;

import java.awt.event.*;
import java.awt.*;

import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.html.*;

public class JTextPaneApp
extends JFrame
{
    public final static int APP_WIDTH = 640;
    public final static int APP_HEIGHT = 400;

    public JTextPane jTextPane;
    public StyleSheet styleSheet;
    public HTMLDocument htmlDocument;
    public HTMLEditorKit htmlEditorKit;

    public javax.swing.text.Element contentElement;

    public JTextPaneApp()
    {
        setSize(APP_WIDTH, APP_HEIGHT);
        setResizable(false);
        setTitle("JTextPane App");

        styleSheet = new StyleSheet();
        styleSheet.addRule("body {font-family: Tahoma; font-size: 11pt; font-style: normal; font-weight: normal;}");
        styleSheet.addRule(".nick {color: blue;}");
        styleSheet.addRule(".normal {color: black;}");

        htmlEditorKit = new HTMLEditorKit();
        htmlEditorKit.setStyleSheet(styleSheet);
        htmlDocument = (HTMLDocument)htmlEditorKit.createDefaultDocument();

        jTextPane = new JTextPane();
        jTextPane.setEditorKit(htmlEditorKit);
        jTextPane.setDocument(htmlDocument);

        try {
            javax.swing.text.Element htmlElement = htmlDocument.getRootElements()[0];
            javax.swing.text.Element bodyElement = htmlElement.getElement(0);
            htmlDocument.insertAfterStart(bodyElement, "<div></div>");

            contentElement = bodyElement.getElement(0);
        } catch (Exception e) {
            e.printStackTrace();
        }


        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());

        contentPane.add(jTextPane, BorderLayout.CENTER);

        addWindowListener
        (
            new WindowAdapter()
            {
                public void windowClosing(WindowEvent e)
                {
                    System.exit(0);
                }
            }
        );

        StringBuffer sbHtml = new StringBuffer();
        sbHtml.append("<div>");
        sbHtml.append("<font class=\"nick\">").append("Peter said: ").append("</font>");
        sbHtml.append("<font class=\"normal\">").append("Hello, world!").append("</font>");
        sbHtml.append("</div>");

        try {
            htmlDocument.insertBeforeEnd(contentElement, sbHtml.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args)
    {
        try {
            JTextPaneApp jTextPaneApp = new JTextPaneApp();
            jTextPaneApp.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
The string "Peter said: " should be rendered in blue and the string "Hello, world!" should be rendered in black, but everything is rendered in black. The body rule does work but the other rules don't seem to work. Can anybody help me, please?

Comments

damorgan
You are using a non-Oracle certified tool to access an Oracle database on a non-supported operating system.

Why not go with supported tools and supported configurations? They have the advantage that they work.
646831
Thanks for your reply.

Here is the complete situation we are in.

We are trying to connect to Oracle's TimesTen Database from a Rails Application.
I cannot find Rails Adapter to connect to TimesTen Database.
But there is odbc adapter for Rails.

So we are planning to configure DSN here on linux for Remote Oracle and trying to connect to the remote database.

If not possible we have to try atleast both Rails App and TimesTen on the same machine.
Then also we need to go thru ODBC-adapter.

we are using isql as a simple tool to test DSN.

Thanks,
164043
The problem is not in the supportability, the problem lies in the fact that this driver is untested and doesn't work.
I was able to successfully do the trick with the ODBC driver for 10.2 but the 11g version doesn't work, it's missing
a symbol. For your information, this driver doesn't work even on OEL 5.2, which is supported. Just blasting people for using the unsupported combination will not change the fact that neither dg4odbc nor the ODBC
driver itself are working. Both are hopelessly broken.

If you ever asked yourself why is the adoption of 11g so slow, the answer is that is largely untested and significant parts of it don't work. I had a problem with fast switchover to standby which did work in one direction, but could not get back and I still have a problem with ODBC drivers which are programmed sloppily. I suggested my management not to go to 11g for at least another year. New features of 11g are fascinating but the software quality is appalling, to put it mildly. There are show stopping bugs all over the place.

Other than that, my understanding of this forum is that it is intended for a free form exchange of information. Blasting people for testing possibilities doesn't seem like the right answer to me. On the other hand, any
other answer would be inconsistent with Dan Morgan.
1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 28 2005
Added on Dec 18 2004
2 comments
1,917 views