loloof64
loloof64

Reputation: 5392

Java Swing completely rounded JButton (circle outside area can't be clicked nor visible)

I've been trying to implement a completely free bordered JButton :

Is there a simple way to do it in "plain" Swing (without any 3d party library) ? Otherwise, is there a good free (open-source is better of course) 3d party library in order to do this ?

As an example, think about a Red Circle ball : the best interaction I can give to users is that it can't click in the outside area, particularly if the Ball is really big.

Thank you in advance

(I've thought of a component written from scratch with Java2D, and using the Shape contains() method in order to see if the click is good. But I would have 2 main problems :

Upvotes: 3

Views: 2490

Answers (1)

mKorbel
mKorbel

Reputation: 109813

you have three choises

1) every Custom Look and Feels have implements Rounded JComponents, this is safiest way how to do that confortly and maybe correctly too, part of them brings excelent output to the Java Swing GUI and with long Bug history, I'd suggest to use Substance Look & Feel, but is very, so sensitive to EDT

2) you can override whole (Custom Look and Feels already did that) ButtonUI, but your UI_Delegate will be Look and Feel and Native_OS sensitive, meaning example that link I post, works on Windows platform with Metal Look and Feel, if you want to create an cross Platform and cross Look & Feel non-sensitive, then you must to overrive all possible Platforms and Look and Feels

3) create JComponent with Rounded Borders, fill area inside with for example GradientPaint, and then add MouseListener, MouseMotionListener, KeyListener or better write own KeyBindings and create own Model for avoiding the concurency betweens linstening Listeners, then will be your Custom JButton cross Platform and cross Look & Feel non-sensitive

everything .... up to you, much luck

Upvotes: 4

Related Questions