Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / September 2006

Tip: Looking for answers? Try searching our database.

JEditorPane link alink vlink colors

Thread view: 
John - 01 Sep 2006 10:08 GMT
Hello,

Is it possible to make JEditorPane use the correct color for hyperlinks?
I have already read that it's not up to JEditorPane to handle "vlink"
color, it must be done by the user. But for "alink", and at least "link"
color, what must be done to make it work?

Here is an example:

import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JEditorPane;

public class TestLinkColor extends JFrame {

    private JPanel jContentPane = null;
    private JScrollPane jScrollPane = null;
    private JEditorPane jEditorPane = null;

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                TestLinkColor thisClass = new
                                                        TestLinkColor();
                thisClass.
                         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                thisClass.setVisible(true);
            }
        });
    }

    public TestLinkColor() {
        super();
        initialize();
       
        StringBuffer html = new StringBuffer();
       
        html.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
        html.append("<html><head>\n");
        html.append("  <title>Title</title>\n");
        html.append("</head>\n");
        html.append("<body alink=\"#FF0000\" bgcolor=\"#FFFFFF\"
link=\"#00FF00\" text=\"#000000\" vlink=\"#0000FF\">\n");
        html.append("A link: <a href=\"http://bugs.sun.com\">Found a BUG</a>\n");
        html.append("</body></html>\n");
       
        System.err.println(html.toString());
       
        getJEditorPane().setContentType("text/html");
        getJEditorPane().setText(html.toString());
    }

    private void initialize() {
        this.setSize(300, 200);
        this.setContentPane(getJContentPane());
        this.setTitle("JFrame");
    }

    private JPanel getJContentPane() {
        if (jContentPane == null) {
            jContentPane = new JPanel();
            jContentPane.setLayout(new BorderLayout());
            jContentPane.add(getJScrollPane(), BorderLayout.CENTER);
        }
        return jContentPane;
    }

    private JScrollPane getJScrollPane() {
        if (jScrollPane == null) {
            jScrollPane = new JScrollPane();
            jScrollPane.setViewportView(getJEditorPane());
        }
        return jScrollPane;
    }

    private JEditorPane getJEditorPane() {
        if (jEditorPane == null) {
            jEditorPane = new JEditorPane();
        }
        return jEditorPane;
    }
   
}

Thanks
hiwa - 02 Sep 2006 11:02 GMT
John のメッセージ:

> Hello,
>
[quoted text clipped - 84 lines]
>
> Thanks
If they are not defined in HTML 3.1 or before, JEditorPane can't handle
them.
Andrew Thompson - 02 Sep 2006 11:10 GMT
> John のメッセージ:
...
> >         html.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
...
> If they are not defined in HTML 3.1

Did you mean HTML 3.2?  I have never actually seen a page
that claimed to conform to HTML 3.1.

>...or before, JEditorPane can't handle them.

Andrew T.
John - 04 Sep 2006 12:45 GMT
> If they are not defined in HTML 3.1 or before, JEditorPane can't handle
> them.

seems to be HTML 3.2:

http://tinyurl.com/kgekl
or
http://72.14.221.104/search?q=cache:L_RhtLFYW-cJ:java.sun.com/j2se/1.4.2/docs/ap
i/javax/swing/JEditorPane.html+JEditorPane+HTML+3.2+site:java.sun.com&hl=fr&gl=f
r&ct=clnk&cd=1

Andrew Thompson - 04 Sep 2006 13:02 GMT
> > If they are not defined in HTML 3.1 or before, JEditorPane can't handle
> > them.
>
> seems to be HTML 3.2:
..
> http://72.14.221.104/search?q=cache:L_RhtLFYW-cJ:java.sun.com/j2se/1.4.2/docs/ap
i/javax/swing/JEditorPane.html+JEditorPane+HTML+3.2+site:java.sun.com&hl=fr&gl=f
r&ct=clnk&cd=1

Yep.  When I read your post, I went searching Sun for a page that
describes *exactly* what is understood by JEP, but after 2 minutes
failure (for the Sun search engine to produce a result page), gave up.

I am sure I recall that JEP does *not* implement *every* style
understood in HTML 3.2, but I suspect the actual problem here
is that the local class has no 'memory' of (especially) VLINK's
with which to 'remember' what links have been visited.

VLINK/ALINK were sure defined for HTML 3.2
<http://www.w3.org/TR/REC-html32#body>

..but as an aside, did you validate your HTML?  It looked OK to
me, but I am no HTML parser - I suggest it is better when
experimenting (and especially when facing unexpected results)
to keep the HTML as a separate document - specifically so that
it can be validated.  The on-line validator is here..
<http://validator.w3.org/>

Andrew T.
John - 04 Sep 2006 13:46 GMT
vlink is the less important. The most important is "link".

the file: =======================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Title</title>
</head>
<body alink="#FF0000" bgcolor="#FFFFFF" link="#00FF00" text="#000000"
vlink="#0000FF">
A link: <a href="http://bugs.sun.com">link text</a>
</body></html>
=================================================
Result:      Passed validation
File:    upload://Form Submission
Encoding:    utf-8
Doctype:    -//W3C//DTD HTML 3.2//EN

Unknown Parse Mode!

    The MIME Media Type () for this document is used to serve both SGML
and XML based documents, and it is not possible to disambiguate it based
on the DOCTYPE Declaration in your document. Parsing will continue in
SGML mode.

This Page Is Valid -//W3C//DTD HTML 3.2//EN!

Tip Of The Day:
    Use class with semantics in mind

The uploaded document "upload://Form Submission" was checked and found
to be valid -//W3C//DTD HTML 3.2//EN. This means that the resource in
question identified itself as "-//W3C//DTD HTML 3.2//EN" and that we
successfully performed a formal validation using an SGML or XML Parser
(depending on the markup language used).
Andrew Thompson - 04 Sep 2006 14:21 GMT
> vlink is the less important. The most important is "link".
>
> the file: =======================================
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
...
> Result:      Passed validation

That 's the 'good stuff'.  Thanks for confirming.

Not sure how to proceed from here, am interested to
hear from others.

Andrew T.
John - 06 Sep 2006 14:22 GMT
i've found 2 simple workaround: put a style for each A tag or enclose
each A tag with a FONT tag.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Title</title>
</head>
<body alink="#FF0000" bgcolor="#FFFFFF">
A no-color link: <a href="http://bugs.sun.com">link text</a><br>
A red style link: <a style="color: red;" href="http://bugs.sun.com">link
text</a><br>
A red font link: <font color="red"><a href="http://bugs.sun.com">link
text</a></font><br>
</body></html>


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.