的HTML不再的JLabel(和其他部件)的工作 [英] HTML no longer working in JLabel (and other components)

查看:133
本文介绍了的HTML不再的JLabel(和其他部件)的工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我写的,并已运行它相当长的一段Java小程序。在applet我有一堆在其文本内容(这是允许的,并已工作多年)使用HTML的JLabel。我使用HTML的主要原因是允许的JLabel换行符。

I have a java applet that I've written and have been running it for quite a while. In the applet I have a bunch of JLabels that use HTML in their text content (which is allowed, and has been working for years). The main reason I use HTML is to allow line breaks in JLabels.

问题:最近相当的有HTML在他们(有些没有)的JLabel停止显示其文本。我想可能有一些做与最近的Java更新(Java SE 6的更新22,2010年10月 - 12)确保不是100%,但问题似乎并开始左右即可。也许一个bug已经出台?或功能去掉?

The issue: fairly recently the JLabels that have HTML in them (some don't) stopped displaying their text. I think it might have something to do with the recent java update (Java SE 6 Update 22, on 2010-Oct-12) not 100 percent sure, but the problems did seem to start around then. Maybe a bug has been introduced? or feature removed?

我试着用一个JEditorPane,似乎有同样的问题,当含量为HTML。

I tried with a JEditorPane and seemed to have the same issues when the content was HTML.

另外一些需要注意的重要的是你第一次加载(第一次您的Java运行时启动)它工作正常的小程序,但如果刷新网页,然后描述它有问题。

Also something important to note is that the first time you load the applet (first time your java runtime starts) it works FINE, but if you refresh the webpage then it has the issues as described.

有没有人有类似的问题?任何人有任何见解?还是我只是做了愚蠢的事情?

Does anyone have similar issues? anyone have any insights? or am I just doing something dumb?

我做了一个非常简单的测试小程序,然后我可以重现100%的规律性问题(记住,第一次运行时加载它会工作得很好,只有连续刷新将导致问题):

I made a very simple test applet and I can reproduce the issues with 100% regularity (remembering that the first time the runtime loads it will work fine, only successive refreshes will cause the issues):

[HelloWorldApplet.java]

[HelloWorldApplet.java]

import javax.swing.*;

public class HelloWorldApplet extends JApplet
{
    public void init()
    {
        this.add(new JLabel("Hello Everybody (Text)"), java.awt.BorderLayout.NORTH);
        this.add(new JLabel("<html><body>Hello Everybody (HTML)</body></html>"), java.awt.BorderLayout.SOUTH);
    }
}

[HellowWorldApplet.html]

[HellowWorldApplet.html]

<html>
<title>A Test</title>
<body>
    <applet code="HelloWorldApplet.class" width="320" height="120">
        You need Java
    </applet>
</body>
</html>

PS。我一直在测试,主要使用Chrome,但我在IE 8还没有breifly尝试。
此外,我(显然)有最新的Java SE 6更新22作为我的运行时间安装,并有我的JDK匹配的更新。我用简单地编译上面的测试小应用程序:javac的HelloWorldApplet.java

PS. I've been mainly testing using Chrome but I did breifly try in IE 8 also. Also I (obviously) have the latest Java SE 6 update 22 installed as my run time, and have the matching update for my JDK. I compile the above test applet using simply: "javac HelloWorldApplet.java"

推荐答案

浪费了一个下午找这个原因,请参阅以下错误报告<一href=\"http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6993691\">http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6993691

Wasted an afternoon looking for the cause of this, see the following bug report http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6993691

在bug报告中的解决方法是:

The workaround in the bug report is:

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

public class HelloWorldApplet extends JApplet {
    public void init() {
       ParserDelegator workaround = new ParserDelegator();
       applet.add(new JLabel("Hello Everybody (Text)"), java.awt.BorderLayout.NORTH);
       applet.add(new JLabel("<html>Hello Everybody (HTML)</html>"),  java.awt.BorderLayout.SOUTH);
    }
}

这篇关于的HTML不再的JLabel(和其他部件)的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆