File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes custom shaped gui components? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "custom shaped gui components?" Watch "custom shaped gui components?" New topic

custom shaped gui components?

Sanjeev Charla
Ranch Hand

Joined: Apr 02, 2009
Posts: 90

how to create custom shaped gui components . . . please specify some clue . . .
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2454
Old example to get you started:

Sanjeev Charla
Ranch Hand

Joined: Apr 02, 2009
Posts: 90

Thank you. . .

So, That means, if we want a customized component ,then we have to extend that basic API component and override related methods , to get that component as required . . . am i correct . . .?
mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
i actually am looking for ways to do that. because i want to mimick the buttons of firefox 3's back and next buttons (big circle left, weird shape right)

im wondering if there is a way to have a shape object created based on the image of an imageicon, then that would be quicker. but is that possible?

while the left button of firefox can be solved using a rounded button, the right button is the tricky part since it is a different shape.

Website/Java Games:
Tech Blog:
Rob Spoor

Joined: Oct 27, 2005
Posts: 20279

The quick&dirty way:
- use BufferedImage instead of Image; this allows you to read the values for each pixel
- use java.awt.geom.Area as your Shape
- go through each pixel. If it's not transparent create a Rectangle for the pixel. Add the Rectangle to the Area
- when done the Area is a Shape with the contours of your image

I don't know if it's the most efficient way. Alternatives can be found here and here.

How To Ask Questions How To Answer Questions
mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
great! thanks for this, will check this out and let you know

i will make sure the image is PNG so that transparency will be in effect
I agree. Here's the link:
subject: custom shaped gui components?
It's not a secret anymore!