Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting tab size in TableCellRenderer

Tags:

java

text

swing

I have a class which extends DefaultTableCellRenderer, which renders strings in a monospace font, with a particular color. By default, it appears that tabs are not rendered at all (0 spaces). How can I set the tab size and/or cause them to be rendered?

edits: By "tabs" I mean tab characters, which I would just like to be rendered as some number of spaces. Rewriting the string is an option, but I figured there was a better way.

like image 361
DLS Avatar asked Dec 03 '25 20:12

DLS


1 Answers

DefaultTableCellRenderer is a JLabel and does what a JLabel will do. I suggest you make yourself a custom TableCellRenderer and return a JPanel with two or more JLabels laid out appropriately. Alternatively use a JComponent that overrides paintComponent to draw as you wish.

Note: attempting to use HTML in renderers is a really bad idea performance wise.

like image 194
Tom Hawtin - tackline Avatar answered Dec 06 '25 11:12

Tom Hawtin - tackline



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!