- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经搜索过,但还没有看到有人遇到我的情况..,但这就是我遇到的问题:
我正在尝试将一小段 HTML 设置为 JEditorPane 的文本。这是代码:
JEditorPane htmlPane = new JEditorPane();
String imageString = "<img src=\"http://tfwiki.net/mediawiki/images2/thumb/3/37/Optimusg1.jpg/350px-Optimusg1.jpg\"/>";
String description = "<table width=300 border=0 cellspacing=0></table>" + imageString + "</table>";
htmlPane.setContentType("text/html");
htmlPane.setText(description);
但是在我调用 setText 后,我的编辑器 Pane 内容是:
<html>
<head>
</head>
<body>
</body>
</html>
我尝试过添加 <html>
的变体和</html>
到我的字符串的开头和结尾,但没有运气。有人知道我错过了什么或做错了什么吗?
我使用的是 Java 1.7.0_55 32 位。
最佳答案
经过一些测试,我发现......
JEditorPane
之前格式良好。会接受它,事实上,它似乎做了一些自己的验证,删除无效标签......有趣的东西<tr><td>...</td></tr>
进入表格JEditorPane
中反复下载失败。 ,即使相同的 HTML 会在浏览器(如 Chrome)中加载图像1
并添加 alt
标记到图像,这有助于验证实际渲染的某些元素...
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class TestEditorPane {
public static void main(String[] args) {
new TestEditorPane();
}
public TestEditorPane() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
}
JEditorPane htmlPane = new JEditorPane();
String description = "<html><body>Hello<table border=1><tr><td><img alt='Bad' src='http://fc07.deviantart.net/fs70/i/2012/084/c/0/angry_wet_ponies_are_angry____by_tabby444-d4tyfsc.png'/></tr></td></table></body></html>";
htmlPane.setContentType("text/html");
htmlPane.setText(description);
System.out.println(htmlPane.getText());
JFrame frame = new JFrame("Testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(new JScrollPane(htmlPane));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
}
关于java - JEditorPane 不设置任何 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24923129/
我有一个 tomcat 服务器并使用 jedis 客户端连接到它。 我使用的jedis版本是“3.0.0-m1”,tomcat 8.0.15 连接后几个小时后,我看到以下异常。有什么帮助吗? redi
我正在使用 Jedis 连接到 Redis 并将数据推送到列表中。我正在为 JSON 数据使用 rpush。 这些是我执行的步骤: 从 Rabbitmq 获取数据 从 JSON 数据中收集信息并准备一
我正在尝试在 vim 中使用 python-jedi,但目前它完全无法使用,因为它试图在奇怪的时间完成代码。 我添加了以下行: let g:jedi#popup_on_dot = 0 到我的 vim
我正在使用 jedi-vim,输入以下内容后,出现“未找到模式”错误: import numpy numpy. 但是,如果我运行以下 python 脚本,我会得到一长串完成列表: import jed
以下 Java 代码将一百万对整数插入到 Redis 中。 public class JedisInsertion { public static byte[] fromInt(in
我在几个线程中看到了答案,但没有解决我的问题,因为我的问题偶尔会出现,如果有人有任何想法,请问这个问题。 我使用的是jedis 2.8.0版本,Spring Data redis 1.7.5版本。和用
我的 Storm 类使用 Redis 队列来收集数据。 我尝试运行我的 Storm jar storm jar jar_file_name.jar Topology_name configuratio
我通过 jedis 在 java 上有这段代码: int shb1 = jds.storeHypnoBeats(id1, arr1); 调用这个函数: int storeHypnoBeats(Stri
我是 jedi-vim 的新手,我不知道如何跳转其他文件中的函数定义。 jedi-vim 's doc是: 以下是其中的一部分: NOTE: subject to change! let g:jedi
我刚刚注意到,每当我对任何 Delphi 2010 项目进行增量编译 (ctrl-F9) 时,我的项目中引用的所有 JEDI 单元都会重新编译,尽管它们没有以任何方式进行更改。事实上,如果我创建一个新
我正在使用 Jedi usb hid 组件连接 HID 设备并对其进行读取和写入。我无法写入设备。我一直在使用这个代码。 type TReport = Packed record ReportID:
我正在使用 Jedis,我无法直接连接到 Redis,我必须使用代理。我可以使用 socks 代理通过 Jedis 连接到 Redis 吗? 请你帮帮我。 问候。 最佳答案 我一直在寻找解决方案,但找
我在 vim 中通过 YCM 使用 jedi,在我的项目中看到一些奇怪的行为,关于在 jediHttp 服务器上使用 usages 端点。基本上它只能找到我项目中类或函数的一小部分用法。它确实找到了当
我正在尝试连接到我的虚拟机 Redis package nosql; import redis.clients.jedis.Jedis; public class NoSQL { public sta
我在我用作生产者/消费者队列的 Redis 队列之上使用 Java 库 Jedis。它易于设置并且运行良好。 消费者代码如下 List messages = jedis.blpop(0, redisQ
什么是jedis事务执行成功响应? jedis 似乎会返回 1 作为成功响应。如果交易包括两个操作,我的以下代码是否有效? List ret = jedisAdapter.exec(tx, jedi
我在看jedis源码的时候发现 connection = connectionHandler.getConnectionFromSlot(JedisClusterCRC16.getSlot(key))
我在 jedis 客户端的帮助下使用 redis。在此处附加键值设置/获取的代码片段。在这里,我希望我的 jedisPool 只被初始化一次,但它被初始化了多次。不知道我哪里错了。用它挠我的头几天。我
当我像下面的代码一样使用 jedis 时: public class JedisTest extends Sync { private static final String _SET_KEY
我最近不得不使用 Jedis 库,它是一个很棒的库。我知道 Redis 是用 C 编写的,Jedis 只是将 Java 包装在 C 周围吗?光看Jedis源码是想不通的。谁能解释一下? 最佳答案 Je
我是一名优秀的程序员,十分优秀!