我想在JTable列中添加右填充,可以吗? [英] I would like to add a right-padding to a JTable column, is it possible?
问题描述
我想在JTable的一列中添加正确的单元格填充,怎么做?
I want to add right cell-padding to a column in my JTable, how do I do it?
我尝试在线搜索,但似乎找不到确切的答案.
I tried searching online but I can't seem to find a definitive answer for this.
我希望有人能帮助我.
关于, 乍得
推荐答案
使用此处有一个相关示例,说明了JLabel.CENTER
.
Use a custom TableCellRenderer
, and specify setHorizontalAlignment(JLabel.RIGHT)
. There's a related example here that illustrates JLabel.CENTER
.
附录:我的问题是填充而不是对齐.
如果您想在单元格的内部 中填充填充,而不是在单元格之间的,则可以使用渲染器中的边框,如@Guillaume Polet建议的那样.请注意,边框可以是不对称的.下面的示例仅在右侧填充.
If you want the padding inside the cell, rather than between cells, you can use a border in the renderer, as @Guillaume Polet suggests. Note that the border can be asymmetric; the example below pads only on the right.
setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
这篇关于我想在JTable列中添加右填充,可以吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!