Automatic change component width

G

Guest

I have an 'ImageButton' class.
When I change the text of ImageButton to a bigger text
e.g. "OK" -> "All Right!"
I want 'ImageButton' increases its width to keep the new text.
How can I do this?
My class implements these methods:
---------------
public class ImageButton extends Canvas implements MouseListener {
public void paint(Graphics g) { ... }
public Dimension getPreferredSize() { ... }
public Dimension getMinimumSize() { ... }
....
}
 
H

Harald Hein

:

Since you bombard this newsgroup with beginner questions, first some
hints:

1. A newsgroup is not the right palce to learn a language and its
libraries. Consider working through the Java and GUI tutorials on the
Sun Java web site. Also consider buying a good book about Java.

2. comp.lang.java.programmer is not intended for beginner's questions.
The right group is comp.lang.java.help.

3. comp.lang.java.programmer is not intended for GUI questions. The
right group is comp.lang.java.gui.

4. If you don't like this suggestions, don't make an ass out of
yourself. Freaking out will only reduce your chances of getting an
answer in the future.
I have an 'ImageButton' class.

JButton is perfectly capable of displaying images.
When I change the text of ImageButton to a bigger text
e.g. "OK" -> "All Right!"
I want 'ImageButton' increases its width to keep the new text.
How can I do this?

Adjust the data that the get...Size() methods shall return, and
depending on your layout manager, revalidate / pack the container on
which you have placed the button.
both of getPreferredSize() & getMinimumSize() return correct width
for new text but component doesn't automatic resize.
Resize appears when I maximize and restore the Window
What methods simulate these events?

You are lacking essential knowledge about the Java GUI architecture. I
want to suggest again that you work through the GUI tutorials and get a
good book on the subject.
 
G

Guest

Since you bombard this newsgroup with beginner questions, first some
hints:

1. A newsgroup is not the right palce to learn a language and its
libraries. Consider working through the Java and GUI tutorials on the
Sun Java web site. Also consider buying a good book about Java.

2. comp.lang.java.programmer is not intended for beginner's questions.
The right group is comp.lang.java.help.

3. comp.lang.java.programmer is not intended for GUI questions. The
right group is comp.lang.java.gui.

4. If you don't like this suggestions, don't make an ass out of
yourself. Freaking out will only reduce your chances of getting an
answer in the future.

ok! I sent to this newsgroup because it has traffic.
I the future I will send to *.help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top