Java JLabel中的HTML表格单元格中的文本垂直居中 [英] Vertically centering text in HTML table cell in Java JLabel
问题描述
我有一个显示在JLabel中的HTML表格(CSS样式)。我希望单元格的内容(单行,短文本)既水平又垂直居中。水平居中很容易,但我似乎无法垂直居中文本。我已经尝试了 vertical-align:
和 valign:
,其中中间
和 center
参数。我已经看了几个窍门,但没有一个看起来可行,我试过的那些都行不通。
现在我拥有了:
>内联(位于< style>
标记中)CSS: pre> table.outer {
background:#F0F0F0;
border-collapse:collapse;
border:none;
}
td.outer {
border-style:solid;
border-width:1pt;
border-color:#888888;
填充:0pt 0pt 0pt 0pt;
}
table.inner {
border-collapse:collapse;
border:none;
}
td.title {
width:75pt;
背景:#BFBFBF;
填充: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'>当前运行< / p>
< / td>
< / tr>
< / table>
< / td>
< / tr>
< / table>
< / body>
支持 Swing Components中的HTML 为 limited 更改为 3.2 ,但 valign =middle
应该可以。
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>
Support for HTML in Swing Components is limited to 3.2, but valign="middle"
should work.
这篇关于Java JLabel中的HTML表格单元格中的文本垂直居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!