The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
August 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Round Edge Button

Posted by Girish B on August 17, 2000 at 12:43 AM

Hi Kishori,
I tried u r code but still it gives me rectangular button only.
I just want to show it as round edge button(all the corners are rounded one's). Please tell me the exact solution.
Thanx in advance,
Girish

> Hi
> You can set border of a componenny using setBorder ( ) method ( for JButton too ) . You can create different types of border using static methods in BorderFactory class ( javax.swing.BorderFactory ) . YOu can refer to all kind of Borders in javax.swing.Border package. You can also set color of the border and its shadow color and a lot more.... The following example shows you how... You can also combine different types of border...

> Thanx
> Kishori

> //////////////ButtonBorder.java///////////////
> import java.awt.event.*;
> import java.awt.* ;
> import javax.swing.*;
> import javax.swing.border.* ;

> class BFrame extends JFrame {
> public BFrame ( ) {
> setTitle ( "GUI Frame" );
> setSize ( 300, 300 ) ;
> addWindowListener ( new WindowAdapter ( ) {
> public void windowClosing ( WindowEvent e ) {
> System.exit ( 0 ) ;
> } } ) ;
>
> JPanel panel = new JPanel ( );
> JButton etched = new JButton ( "Etched" ) ;
> etched.setBorder ( BorderFactory.createEtchedBorder ( ) ) ;
> panel.add ( etched ) ;
>
> JButton loweredBevel = new JButton ( "Lowered Bevel" ) ;
> loweredBevel.setBorder ( BorderFactory.createBevelBorder ( BevelBorder.LOWERED ) ) ;
> panel.add ( loweredBevel ) ;
>
> JButton raisedBevel = new JButton ( "Raised Bevel" ) ;
> raisedBevel.setBorder ( BorderFactory.createBevelBorder ( BevelBorder.RAISED ) ) ;
> panel.add ( raisedBevel ) ;
>
> JButton coloredBorder = new JButton ( "Colored Border" ) ;
> coloredBorder.setBorder ( BorderFactory.createBevelBorder ( BevelBorder.RAISED, Color.blue, Color.cyan ) ) ;
> panel.add ( coloredBorder ) ;
>
>
> getContentPane().add ( panel ) ;
> }
> }

> public class ButtonBorder {
> public static void main ( String[] args ) {
> BFrame f = new BFrame ( );
> f.show ( );
> }
> }






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us