JEdi​​torPane,文本中图像的对齐

发布于 2025-01-08 02:34:39 字数 592 浏览 6 评论 0原文

_https://i.sstatic.net/W2We5.gif

<img src=\"file:b:/smile.gif\" align=\"middle\">"

_https://i.sstatic.net/VPHzw.gif

<img src=\"file:b:/smile.gif\">

必需:
_https://i.sstatic.net/WlMhG.gif

我需要在 JEditorPane 中对齐图像,并且图像不应影响行的高度。如果我使用align=middle - 图片未对齐并保留对行高的影响。

对于html中类似问题的解决方案,我使用:

<span style=\"background-image: url('file:b:/smile.gif') 50% 50% no-repeat\"> &nbsp;&nbsp;&nbsp;&nbsp;</span>

但此方法在JEditorPane中不起作用。我该如何解决这个问题?

_https://i.sstatic.net/W2We5.gif

<img src=\"file:b:/smile.gif\" align=\"middle\">"

_https://i.sstatic.net/VPHzw.gif

<img src=\"file:b:/smile.gif\">

Required:
_https://i.sstatic.net/WlMhG.gif

I need to align the image in the JEditorPane and the image should not affect the height of rows. If I use align=middle - the picture is not aligned and retained influence on the height of rows.

To a solution of similar problems in html I use:

<span style=\"background-image: url('file:b:/smile.gif') 50% 50% no-repeat\">     </span>

But this method does not work in JEditorPane. How can I solve this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瀟灑尐姊 2025-01-15 02:34:39

要将图像对齐到 JEditorPane 的中间,您可以使用类似以下的内容:

editPane.setText("<html><p style = \"text-align:center;\"><img src = " + 
        "\"http://gagandeepbali.uk.to/gaganisonline/images/" + 
        "editsystemvariable2.png\" alt = \"pic\" /></p></html>\n");

这里的 text-align 属性可以为您做到这一点。关于图像不应影响行的大小,我不确定您的意图,但如果我理解正确,那么您可以在 < 中为图像提供固定的宽度和高度。 img> 标签。

在这里,我使用了这段代码,请告诉我除了这段代码中找到的内容之外,您是否还需要其他内容。希望我能提供帮助,

import java.awt.*;
import javax.swing.*;

public class EditorPaneTest extends JFrame
{
    public EditorPaneTest()
    {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationByPlatform(true);        

        JEditorPane editPane = new JEditorPane();
        JScrollPane scrollPane = new JScrollPane(editPane);     

        editPane.setContentType("text/html");

        editPane.setText("<html><p style = \"text-align:center;\">Hello there, How you doing ?<img src = " + 
                                            "\"http://s018.radikal.ru/i504/1202/03/c01a2e35713f.gif" + 
                                                "\" alt = \"pic\" width = \"15\" height = \"15\" />I guess all is good!!" +
                                                        "<br />I hope this is what you wanted!! " + 
                                                                    "<img src =  \"http://s018.radikal.ru/i504/1202/03/c01a2e35713f.gif" + 
                                                "\" alt = \"pic\" width = \"15\" height = \"15\" /> Hope this works for you :-)</p></html>\n");

        add(scrollPane, BorderLayout.CENTER);
        setSize(400, 300);
        setVisible(true);
    }

    public static void main(String... args)
    {
        SwingUtilities.invokeLater(new Runnable()
        {
            public void run()
            {
                new EditorPaneTest();
            }
        });
    }
}

这是输出图像:

EditorPane's View

更多使用此 笑脸图像。我已经为您删除了图像中多余的底部空间。

To align your Images to the Middle of the JEditorPane, you can use something like this :

editPane.setText("<html><p style = \"text-align:center;\"><img src = " + 
        "\"http://gagandeepbali.uk.to/gaganisonline/images/" + 
        "editsystemvariable2.png\" alt = \"pic\" /></p></html>\n");

Here the text-align property can do that trick for you. And about that thing that image should not affect the size of the row, I am not sure about your intentions on that, but if I understood you right then you can provide a fixed width and height to your images in the <img> tag.

Here I used this code, and tell me if you desire something else, other than what you find in this code. Wish I could help,

import java.awt.*;
import javax.swing.*;

public class EditorPaneTest extends JFrame
{
    public EditorPaneTest()
    {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationByPlatform(true);        

        JEditorPane editPane = new JEditorPane();
        JScrollPane scrollPane = new JScrollPane(editPane);     

        editPane.setContentType("text/html");

        editPane.setText("<html><p style = \"text-align:center;\">Hello there, How you doing ?<img src = " + 
                                            "\"http://s018.radikal.ru/i504/1202/03/c01a2e35713f.gif" + 
                                                "\" alt = \"pic\" width = \"15\" height = \"15\" />I guess all is good!!" +
                                                        "<br />I hope this is what you wanted!! " + 
                                                                    "<img src =  \"http://s018.radikal.ru/i504/1202/03/c01a2e35713f.gif" + 
                                                "\" alt = \"pic\" width = \"15\" height = \"15\" /> Hope this works for you :-)</p></html>\n");

        add(scrollPane, BorderLayout.CENTER);
        setSize(400, 300);
        setVisible(true);
    }

    public static void main(String... args)
    {
        SwingUtilities.invokeLater(new Runnable()
        {
            public void run()
            {
                new EditorPaneTest();
            }
        });
    }
}

And here is the output image :

EditorPane's View

MoreOver use this Smiley Image. I had removed the extra bottom space from the image for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文