Buttons with rounded edges  
Author Message
theodosisx





PostPosted: 2004-6-23 21:38:00 Top

java-programmer, Buttons with rounded edges How can i make a JButton Object to have rounded edges.
Have anyone a simple example?
 
VisionSet





PostPosted: 2004-6-23 23:33:00 Top

java-programmer >> Buttons with rounded edges
"Theodosis Ekizoglos" <email***@***.com> wrote in message
news:email***@***.com...
> How can i make a JButton Object to have rounded edges.
> Have anyone a simple example?

The easiest way is probably to do:

myJButton.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
myJButton.setIcon(...);
myJButton.setPressedIcon(...);



 
Roedy Green





PostPosted: 2004-6-24 2:28:00 Top

java-programmer >> Buttons with rounded edges On 23 Jun 2004 06:37:35 -0700, email***@***.com (Theodosis
Ekizoglos) wrote or quoted :

>How can i make a JButton Object to have rounded edges.
>Have anyone a simple example?

you could use a transparent icon.

see http://mindprod.com/jgloss/jbutton.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
 
phusion-88





PostPosted: 2004-6-24 4:07:00 Top

java-programmer >> Buttons with rounded edges i'm not sure how to do it specifically but
some look and feels give the rounded button effect.
just thought i'd mention it just in case that is
what you were looking for.
www.javootoo.com
 
 
theodosisx





PostPosted: 2004-6-24 16:18:00 Top

java-programmer >> Buttons with rounded edges email***@***.com wrote in message news:<email***@***.com>...
> i'm not sure how to do it specifically but
> some look and feels give the rounded button effect.
> just thought i'd mention it just in case that is
> what you were looking for.
> www.javootoo.com

Thank you but:

Using (runded) images to make the illusion of a rounded JButton
isn't a "clear" solution since in this case I can't put text in
the JButton. And this is not the only disadvantage.

There is L&F managers that do the job but what if I want to have
some rounded buttons and some normal buttons?

For me is the best when I create a class JRoundedButton that overrides
the apropriate method for designing a JButton but I cann't go
deeper in this direction. I need help from someone who already did
something like that.
 
 
Adam





PostPosted: 2004-6-24 17:14:00 Top

java-programmer >> Buttons with rounded edges
"Theodosis Ekizoglos" <email***@***.com> wrote in message
news:email***@***.com...
> email***@***.com wrote in message
news:<email***@***.com>...
> > i'm not sure how to do it specifically but
> > some look and feels give the rounded button effect.
> > just thought i'd mention it just in case that is
> > what you were looking for.
> > www.javootoo.com
>
> Thank you but:
>
> Using (runded) images to make the illusion of a rounded JButton
> isn't a "clear" solution since in this case I can't put text in
> the JButton. And this is not the only disadvantage.
>
> There is L&F managers that do the job but what if I want to have
> some rounded buttons and some normal buttons?
>
> For me is the best when I create a class JRoundedButton that
overrides
> the apropriate method for designing a JButton but I cann't go
> deeper in this direction. I need help from someone who already did
> something like that.

What you want to do is to override paintComponent(Graphics g)
in your JRoundedButton class and do all the painting yourself there.
Kind of:
class JRoundedButton extends JButton
{
public void paintComponent(Graphics g)
{
int radius = 10;
g.setColor(getBackground());
//here comes your round button
g.fillOval(0,0,getWidth(),getHeight(),radius,radius);
//and now obtain text of the button, calculate its position
//regarding aligning and paint it with foreground color
}
}

That way you would have the same look of your round buttons
regardless of used L&F. I'd say it is not the best idea.

I would suggest creating a Border implementation
that would just take care of rendering round border
around your buttons.
Whenever you'd want a round button you would
setBorder(new MyRoundBorder())
on the one that you want to be round.

So you would not have to do all the rendering yourself,
just the border. And your RoundBorder could use
settings of the current L&F.

HTH,
Adam


 
 
ak





PostPosted: 2004-6-25 14:59:00 Top

java-programmer >> Buttons with rounded edges > For me is the best when I create a class JRoundedButton that overrides
> the apropriate method for designing a JButton but I cann't go
> deeper in this direction. I need help from someone who already did
> something like that.

java.awt.geom.Class RoundRectangle2D could help you.
you can also use it to set the clip of Grapihcs while painting.

--
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader