JButton text becomes "...."

Hi, When a JButton has a simple text such as "S" but it is small enough that its displayed text becomes "...".How can I get rid of the "..." and display the "S"?
[182 byte] By [skymanagera] at [2007-11-27 0:19:19]
# 1
hi,I think thats related to your JPanel size, when the TextFields do not have enough space in JPanel, they cannot be fully displayed and becomes "...."Expand your contentPane or JPanel or whatever pane you put your Label on. Its either too high or too width for the Panel.
program_grunta at 2007-7-11 22:10:47 > top of Java-index,Desktop,Core GUI APIs...
# 2
button.setMargin(new Insets(0,0,0,0));and/orbutton.setFont(button.getFont().deriveFont(6f));//experiment with 6, 8 10 etc
Michael_Dunna at 2007-7-11 22:10:47 > top of Java-index,Desktop,Core GUI APIs...
# 3

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.

skymanagera at 2007-7-11 22:10:47 > top of Java-index,Desktop,Core GUI APIs...
# 4

> 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.

camickra at 2007-7-11 22:10:47 > top of Java-index,Desktop,Core GUI APIs...
# 5

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>");

Michael_Dunna at 2007-7-11 22:10:47 > top of Java-index,Desktop,Core GUI APIs...
# 6
I guess I have to custom create a new button.Thank you all.
skymanagera at 2007-7-11 22:10:47 > top of Java-index,Desktop,Core GUI APIs...