Skip to main content

circle button

8 replies [Last post]
ahi
Offline
Joined: 2008-06-11
Points: 0

hello,
Does he know anyone how can i do the button circle. I thing that i have to go to the source but i dont know how can i do this.
thanks

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ahi
Offline
Joined: 2008-06-11
Points: 0

I would to change the source of the rectangle button but i dont know how can i see the source of the rectangle button. If i do an image as a button is quit easy. I would like to do with this way.

Shai Almog

You don't need to change the source of the button, you can just
derive from it and override paint to draw the button the way you want.

If you want to change the way all buttons are rendered derive from
DefaultLookAndFeel and override the drawButton method.

Thanks,
Shai.

> I would to change the source of the rectangle button but i dont
> know how can i see the source of the rectangle button. If i do an
> image as a button is quit easy. I would like to do with this way.
> [Message sent by forum member 'ahi' (ahi)]
>
> http://forums.java.net/jive/thread.jspa?messageID=280309
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

ahi
Offline
Joined: 2008-06-11
Points: 0

thanks for your answer Shai
I would like to change only the button that i use and not all. But do you know what i have to write in my class to change the shape of the button and to do round.Do you know any useful link?
thanks

Shai Almog

I'll try to write something more detailed in my blog later on but in
general what you can do is this (untested):

class RoundButton extends Button {
public RoundButton() {
// set padding to be large enough for the round button:
getStyle().setPadding(10, 10, 10, 10);
}

protected Dimension calcPreferredSize() {
// since the button is round width and height must be
identical
Dimension d = super. calcPreferredSize();
int size = Math.max(d.getWidth(), d.getHeight());
d.setWidth(size);
d.setHeight(size);
return d;
}

protected void paintBorder(Graphics g) {
if(isFocusPainted() && hasFocus()) {
g.setColor(getStyle().getFgSelectionColor());
} else {
g.setColor(getStyle().getFgColor());
}
g.drawArc(getX(), getY(), getWidth(), getHeight(), 0, 360);
}
}

As I said, untested but it should give you a starting point.

Thanks,
Shai.

> thanks for your answer Shai
> I would like to change only the button that i use and not all. But
> do you know what i have to write in my class to change the shape of
> the button and to do round.Do you know any useful link?
> thanks
> [Message sent by forum member 'ahi' (ahi)]
>
> http://forums.java.net/jive/thread.jspa?messageID=280312
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

ahi
Offline
Joined: 2008-06-11
Points: 0

thanks Shai i will wait to give me the starting point.
But please, try to be as soon as possible.

chen

Hi,
You can check out Shai's blog post on this:
http://lwuit.blogspot.com/2008/06/many-roads-to-round-buttons-advanced.html

Regards,
Chen

lwuit-users@mobileandembedded.org wrote:
> thanks Shai i will wait to give me the starting point.
> But please, try to be as soon as possible.
> [Message sent by forum member 'ahi' (ahi)]
>
> http://forums.java.net/jive/thread.jspa?messageID=280319
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

Matteo Mazzotti

If what you are trying to do is a round button, what about creating a button
with no border drawn and setting a transparent round image as its icon?

Matteo

> hello,
> Does he know anyone how can i do the button circle. I thing
> that i have to go to the source but i dont know how can i do this.
> thanks
> [Message sent by forum member 'ahi' (ahi)]
>
> http://forums.java.net/jive/thread.jspa?messageID=280305
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

Shai Almog

Good answer.
Try setting the transparent round image as its bgImage in the style
and obviously set padding to be large enough so the text doesn't
slide from the edges.
You can play with this in the resource editor and see it live.

Another, more complex option is to override button painting either by
deriving from Button or by extending the DefaultLookAndFeel class and
installing a new look and feel.

Thanks,
Shai.

> If what you are trying to do is a round button, what about creating
> a button
> with no border drawn and setting a transparent round image as its
> icon?
>
> Matteo
>
>> hello,
>> Does he know anyone how can i do the button circle. I thing
>> that i have to go to the source but i dont know how can i do this.
>> thanks
>> [Message sent by forum member 'ahi' (ahi)]
>>
>> http://forums.java.net/jive/thread.jspa?messageID=280305
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net