Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove default padding in JTextPane on Windows

For displaying information on a Java Swing GUI I use a mixture of JLabel components and JTextPanes.

As you can see in the following image, all labels are JLabels except for the one in the bottom right corner which is marked red and yellow. This one's a JTextPane, cause I don't know the text length before rendering and it has to wrap (which is not working in a JLabel, right?).

Different Rendering on Windows and Mac

The left column is aligned right and has a right-margin of 5, the right column is aligned left with zero margin.

In Eclipse WindowBuilder and on Windows 7 rendering, the JTextPane obviously has a small padding which I can't remove.

Surprisingly, this padding isn't shown on my Mac (Mountain Lion) and the JTextPane is aligned perfectly well.

Is there any way to achieve the same aligned look on Windows and on Mac? And why on earth does the JTextPane component has this annoying padding on windows?

like image 540
ToFi Avatar asked Oct 30 '25 09:10

ToFi


1 Answers

Use textPane.getMargin()/setMargin() but actually it's defined by L&F

like image 109
StanislavL Avatar answered Nov 02 '25 00:11

StanislavL



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!