I need to make the date parts (dd, MMMM, yyyy) to be vertically aligned. I asked a question at Fixed length of month and day in date format? to insert padding letters, but I found that it doesn't help in case of proportional font (the width of the letters are different). For example, with Lucida Fax font:
Making different labels for different date parts is considering but it's too manual. It's hard to make the text wrapped if the column width is small....
Thanks
note as for all Renderers (excluding preparedRenderer)you have to/be sure that you have to call that after any column/row changes in
JTable
here you can set BackGround, ForeGround for TableCell
Thanks for your answers. I found for myself a solution that uses JTextPane as a TableCellRenderer, then define the tabstop values, and use tabs in formatting date. It seems ok for my requirement and also have other features of normal text field such as word wrapping...
As suggested by @mKorbel, a suitable
TableCellRenderer
is the right choice, but you may have to overridepaintComponent()
and render the text using the graphics context'sFontMetrics
as shown here.If numeric months are acceptable, most proportionally-spaced fonts give digit glyphs the same constant advance.