I'm trying to do something which I'd think would be fairly easy but can't find a straight forward answer to. Basically I want to change a JPanel's default shape to a circular shape (or any other shape other than a rectangle).
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
This link should help you . It has examples for Windows shapes and effects in JAVA: http://today.java.net/pub/a/today/2008/03/18/translucent-and-shaped-swing-windows.html
Read this article: http://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html
It shows in details how to create oval transparent windows.
You will need to provide your own custom painting routines.
The other problem you will have is getting the layout managers to work with it, but you can supply your own insets to provided an area within the panel that can safely used
You'll also want to make the component transparent, to allow the area outside the circle position of the component to be transparent.
Check out
JCompnent#getInsets
You might need to also manipulate the clipping rectangle of the
Graphics
context. This is tricky and dangerous and if you can avoid it, I would.Updated with example
If you want only layout to be circle you can use circle layout:
You can use it like this: