Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / June 2004

Tip: Looking for answers? Try searching our database.

Buttons with rounded edges

Thread view: 
Theodosis Ekizoglos - 23 Jun 2004 14:37 GMT
How can i make a JButton Object to have rounded edges.
Have anyone a simple example?
VisionSet - 23 Jun 2004 16:32 GMT
> 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(...);

--
Mike W
Roedy Green - 23 Jun 2004 19:28 GMT
>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

Signature

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

phusion-88@excite.com - 23 Jun 2004 21:06 GMT
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
Theodosis Ekizoglos - 24 Jun 2004 09:17 GMT
> 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 - 24 Jun 2004 10:13 GMT
> > i'm not sure how to do it specifically but
> > some look and feels give the rounded button effect.
[quoted text clipped - 15 lines]
> 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 - 25 Jun 2004 07:58 GMT
> 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.

Signature

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.