File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes making buttons circular Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "making buttons circular" Watch "making buttons circular" New topic
Author

making buttons circular

Chris Dancy
Ranch Hand

Joined: Feb 14, 2006
Posts: 136
hey guys, im wondering if theres an easy way to make jbutton circular instead of rectangular. Suppose if i have a:

class Mybutton extends JButton{

}
im guessing i would have to override paintComponent but im not too good on the swing side of things. If anyone has any suggestions let me know.

Sincely,
Chris Dancy


("Anger is not an emotion, its a symptom of fear.")
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
http://java.sun.com/developer/TechTips/1999/tt0826.html
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

FYI - the buttons created from that how to that was linked will look like poo. My advice to creating round buttons is just use images. Create 3 images for each button (unpressed, pressed, and disabled) setting each for each state of the JButton. Remove the JButton's default border and you got yourself a whatever shape you want button.

Yes, this takes a bit of creative know how in an image editor, but I still think it's easier than doing it with a custom paint() method.


GenRocket - Experts at Building Test Data
Chris Dancy
Ranch Hand

Joined: Feb 14, 2006
Posts: 136
thanks guys
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
the round button looks OK if you change paintComponent() to this

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Michael, I'll have to give that a shot and see what it looks like. I've tried in the past to make the buttons look better by drawing them myself but I am not very good with the graphics API. Which is why I think using images is easier.

I wonder if there is any performance difference in rendering it with graphics or using pre-made images. Anyone have any stats on that?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: making buttons circular