简体   繁体   English

JEdi​​torPane 内图像上的文本

[英]Text over an image inside a JEditorPane

Is there any way to add an image with a text overlaying it in a JEditorPane ?有没有办法在JEditorPane添加带有文本的图像?

The following mark-up that was supposed to work:以下标记应该有效:

<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> 

Does not work when used as the text of the JEditorPane (type "text/html" ).用作JEditorPane的文本时不起作用(键入"text/html" )。

While camickr is (mostly - Swing HTML rendering supports a sub-set of HTML 3.2) correct, it is the limited support for CSS letting you down here.虽然 camickr 是(主要是 - Swing HTML 渲染支持 HTML 3.2 的一个子集)是正确的,但它对 CSS 的有限支持让您失望。

This HTML/CSS works.这个 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>";

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM