java - JEditorPane 内图像上的文本
问题描述
有没有办法添加一个带有文本覆盖的图像JEditorPane
?
以下应该起作用的标记:
<html>
<head>
<div width='150' height='150' style='position: relative;'>
<img src='img_snow_wide.jpg' style='width: 100%; height: 100%; object-fit: cover;' />
<div style='position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);'>
BLAH
</div>
</div>
</body>
</html>
JEditorPane
用作(type "text/html"
)的文本时不起作用。
解决方案
虽然 camickr(主要是 Swing HTML 渲染支持 HTML 3.2 的子集)是正确的,但它对 CSS 的有限支持让您失望。
这个 HTML/CSS 有效。
String html =
"<html>"
+ "<body>"
+ "<div style='width: 370px; height: 220px; color: white; "
+ "background-image: url(https://i.stack.imgur.com/lxthA.jpg);'>"
+ "<p style='text-align: center;'>Observatory Silhouette!</p>"
+ "</div>"
+ "</body>"
+ "</html>";
推荐阅读
- java - 使用hibernate / postgres获取自动递增主键的问题
- mailchimp - Mailchimp 动态内容:在订阅电子邮件中添加自定义链接
- python - Django:表单验证 - 日期不过去和用户唯一的日期
- python - 导入模块系统(Python源码分析)
- java - 如何在 Netbeans 中使 JButton 无边界?
- tableau-api - Tableau - 查找索引成员重叠
- ios - 使用 iOS UIKIT,您可以在演示完成之前调用 dismiss() 吗?
- angular - Angular 和 CharJS - 错误类型错误:无法读取未定义的属性“15”
- c# - 添加记录时使所有列可编辑,而现有记录仅允许编辑某些列
- python - 使用 Regex (Python) 查找单词中所有可能的 5 个字母组合