I have already set the button.setMargin(new Insets(0,0,0,0)) but not help.
I do not want to expand the width
I do want to not showing "..." but most of the left part of the text. For example, if "Cancel" cannot be display completely, I want it to display "Canc". Just anything it can display within the given width.
> if "Cancel" cannot be display completely, I want it to display "Canc".
As you see JLabel will replace the truncated characters with "...".
Other components, like JTextField will paint partial characters.
If you want to only paint whole characters then you will need to create a custom component and to your own painting of the characters.
You would need to use the FontMetrics class of the Graphics component and then determine the size of each character before painting it to make sure it doesn't exceed the width of the space available.
if, as per your first post, you are having trouble with just a letter e.g. S,
you will need to reduce the font size.
if you want to display whatever of 'Cancel' can be displayed, experiment with html
JButton btn = new JButton("<html>Cancel</html>");