Java JLabel 中 HTML 表格单元格中的文本垂直居中
我有一个显示在 JLabel 中的 HTML 表格(带有 CSS 的样式)。我希望单元格的内容(单个短行文本)水平和垂直居中。水平居中很容易,但我似乎无法将文本垂直居中。我尝试过使用 middle
和 center
参数来使用 vertical-align:
和 valign:
。我已经研究了一些技巧,但似乎没有一个可行,而且我尝试过的那些技巧也不起作用。
我现在拥有的:
内联(在 标签中)CSS:
table.outer {
background:#F0F0F0;
border-collapse:collapse;
border:none;
}
td.outer {
border-style:solid;
border-width:1pt;
border-color:#888888;
padding:0pt 0pt 0pt 0pt;
}
table.inner {
border-collapse:collapse;
border:none;
}
td.title {
width:75pt;
background:#BFBFBF;
padding:1.5pt 0pt 1.5pt 0pt;
}
HTML 的相关部分:
<body bgcolor=#F0F0F0>
<table class='outer'>
<tr>
<td class='outer' valign=top>
<table class='inner'>
<tr>
<td class='title' rowspan=3>
<p class='title'>Current Run</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
I have an HTML table (styles with CSS) that is displayed in a JLabel. I would like the contents (a single, short line of text) of the cells to be both horizontally and vertically centered. Horizontal centering is easy, but I cannot seem to center the text vertically. I've tried vertical-align:
and valign:
with both middle
and center
arguments. I've looked at several of the tricks, but none of them seemed doable, and the ones I tried didn't work.
What I have now:
Inline (in the <style>
tag) CSS:
table.outer {
background:#F0F0F0;
border-collapse:collapse;
border:none;
}
td.outer {
border-style:solid;
border-width:1pt;
border-color:#888888;
padding:0pt 0pt 0pt 0pt;
}
table.inner {
border-collapse:collapse;
border:none;
}
td.title {
width:75pt;
background:#BFBFBF;
padding:1.5pt 0pt 1.5pt 0pt;
}
The relevant portion of the HTML:
<body bgcolor=#F0F0F0>
<table class='outer'>
<tr>
<td class='outer' valign=top>
<table class='inner'>
<tr>
<td class='title' rowspan=3>
<p class='title'>Current Run</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
支持 Swing 组件中的 HTML 限制至3.2,但
valign="middle"
应该可以。Support for HTML in Swing Components is limited to 3.2, but
valign="middle"
should work.