setIcon question

13 views
Skip to first unread message

sauceypan

unread,
Nov 3, 2011, 9:59:05 AM11/3/11
to AsWing Discuss
I'm having an issue with setting an icon for my JButton using .png
files. The .png images are 37x37 pixels. I therefore made a JButton of
size 37x37 and then set the icon as follows:
button1.setIcon(new AssetIcon(new Bitmap( "my zoom in image.png") as
DisplayObject));

The problem is that the image does not appear centered as I noticed
that the rounded corners are slightly cutoff.
I therefore reduced the size of the bitmap by one pixel and it
visually looks much better as follows:

button2.setIcon(new AssetIcon(new Bitmap("my zoom in image.png") as
DisplayObject, 36, 36, true));



Thanks

iiley

unread,
Nov 4, 2011, 12:08:06 AM11/4/11
to aswing-...@googlegroups.com
Hi, you should let your button self count size.(do not set a fixed size to it)

2011/11/3 sauceypan <sauc...@gmail.com>



--
-iiley
Burstyx Studio Limited

sauceypan

unread,
Nov 7, 2011, 4:41:00 PM11/7/11
to AsWing Discuss
Hi thanks for the reply,
However if I dont set a fixed size to the button it simply doesn't
display. For example:


button13 = new JButton();
button13.setLocation(new IntPoint(469, 0));
button13.setIcon(new AssetIcon(new Bitmap("my_image.png") as
DisplayObject));
append(button13);

The JButton is not visible at all. Is there something I must do first
for the button to display? I'm using an EmptyLayout if that's
relevant.




On Nov 3, 11:08 pm, iiley <iiley.c...@gmail.com> wrote:
> Hi, you should let your button self count size.(do not set a fixed size to
> it)
>
> 2011/11/3 sauceypan <saucey...@gmail.com>

iiley

unread,
Nov 8, 2011, 12:38:40 AM11/8/11
to aswing-...@googlegroups.com
If you use EmptyLayout, please do this additional:
button12.setSize(button12.getPreferredSize());

2011/11/8 sauceypan <sauc...@gmail.com>
Reply all
Reply to author
Forward
0 new messages