杰拉贝尔:如何在两个跨度标签之间获得空间

问题描述 投票:0回答:1
import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.SwingUtilities; import javax.swing.WindowConstants; public class HTMLabelTryout { private static final String TEXT = "<html><span style=\"font-size:24px; margin-right:16px; color:#007f9c\">This is a paragraph.</span>" + "<span style=\"font-size:16px\">This is another paragraph.</span></html>"; private static final String TEXT2 = "<html><p style=\"font-size:24px; margin-bottom:16px; color:#007f9c\">This is a paragraph.</p>" + "<p style=\"font-size:16px;\">This is another paragraph.</p></html>"; public static void main(String[] args) { SwingUtilities.invokeLater(new HTMLabelTryout()::showFrame); } private void showFrame() { JFrame frm = new JFrame(); frm.add(new JLabel(TEXT), BorderLayout.PAGE_START); frm.add(new JLabel(TEXT2), BorderLayout.PAGE_END); frm.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frm.setSize(900, 400); frm.setLocationRelativeTo(null); frm.setVisible(true); } }

秒文本看起来还不错,但首先,我在两个跨度之间没有空间(宽容/边缘左指令被忽略)。有什么想法,如何在挥杆中两个跨度之间获得16px的水平差距?
P.S。我知道,我可以在跨越之间添加一些非破裂的空间标签以获得一个空间,但这并不精确并且看起来很丑陋。

P.P.S。由于某些原因,我必须在这里使用HTML,并且不能使用2个Jlabel解决方案切换到JPANEL。

HTML跨度是一个内联元素,它将始终忽略框模型中的边距/填充。 为了获得符合布局的框模型的内联元素,您需要将它们调整为

display: inline-block

,但是由于Swing使用HTML 3.2(古老的超越信念),所以我不确定HTML 3.2所支持的

inline-block
java html swing jlabel
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.