Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

jbutton with round corners

1,656 views
Skip to first unread message

Joel Nylund

unread,
Aug 11, 1998, 3:00:00 AM8/11/98
to
There has to be an easy way to do this, I want the borders corder to be
rounded instead of square.

any ideas?

(please send email also)
thanks
Joel

--
*****************************************************************
Joel Nylund
jny...@ami.net
"Remember, a flute without a hole is not a flute, but a donut
without a hole is a danish"
*****************************************************************

Dino Fancellu

unread,
Aug 11, 1998, 3:00:00 AM8/11/98
to
Yes, you need to write a new ButtonUI,

Have a look at the source, for example MetalButtonUI.java

Dino.

James Tan

unread,
Aug 12, 1998, 3:00:00 AM8/12/98
to Joel Nylund
Joel Nylund wrote:

The easiest way is to draw your own circular GIF graphic with a transparent
background.
One 'unpressed' and one 'pressed'.
Place the icons onto the button and set the button transparent and remove
the border.

Eg:
JButton button = new JButton( new ImageIcon( ..unpressicon.. ) );
button.setPressedIcon( new ImageIcon( ..pressicon.. ) );
button.setOpaque( false );
button.setBorder( null );

Now your button will appear to look round.

--
Regards,
James Tan

May the force be with you... Always...
--------------------------------------------------
Homepage: http://www.post1.com/home/james.tan
Personal Email: jame...@earthling.net
Office Email: jame...@cls.uob.com.sg
ICQ Number: 2618988
--------------------------------------------------

Joel Nylund

unread,
Aug 12, 1998, 3:00:00 AM8/12/98
to
I wanted to do that, but the problem is that the image icon is one size, for
different text lengths I need different button sizes, just like normal buttons.

thanks
Joel

James Tan

unread,
Aug 13, 1998, 3:00:00 AM8/13/98
to
Joel Nylund wrote:

> I wanted to do that, but the problem is that the image icon is one size, for
> different text lengths I need different button sizes, just like normal buttons.
>
> thanks
> Joel

What about creating your own border by extending from AbstractBorder?
You can use graphics object from the paintBorder() method to do your own round
corner rectangle.
Then just set the border of the buttons to your own.

James Tan

unread,
Aug 13, 1998, 3:00:00 AM8/13/98
to
James Tan wrote:

> Joel Nylund wrote:
>
> > I wanted to do that, but the problem is that the image icon is one size, for
> > different text lengths I need different button sizes, just like normal buttons.
> >
> > thanks
> > Joel
>
> What about creating your own border by extending from AbstractBorder?
> You can use graphics object from the paintBorder() method to do your own round
> corner rectangle.
> Then just set the border of the buttons to your own.
>

Just to add on, the problem with this is when you switch between different L&F, you
have a problem.
Assuming you're using Metal L&F the border you've create may look differently from
say Motif L&F.
Also, if Swing decided to change the way their button border looks, you've had it!

Maybe doing your own ButtonUI and sticking to it may solve your problem, as suggested
by Dino.

0 new messages