Google Answers Logo
View Question
 
Q: Java - Look and Feel ( No Answer,   1 Comment )
Question  
Subject: Java - Look and Feel
Category: Computers > Programming
Asked by: javacookie-ga
List Price: $10.00
Posted: 28 Mar 2005 04:53 PST
Expires: 27 Apr 2005 05:53 PDT
Question ID: 501324
Hi there,

I am new to java look and feel but have managed to do some basic stuff
myself.

I have created my own look and feel class which I change default colour etc
etc.

I am now wanting to move on and create my own ButtonUI class.  I have done
this and allowed it to extend basic buttonUI class.  At the moment I have
just got the code in there from metal look and feel and it all works fine.

I am wanting to change myButtonUI to give my button rounded corners etc
but haven't really got much of an idea what to change etc. 

Is it posible you could give me the code i could put in there which
would give me rounded corners on the buttons.

I think this would go in the paint method.

Thanks In Advance for you help.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Java - Look and Feel
From: divineflight-ga on 30 Mar 2005 16:36 PST
 
You can't magically give a button a round look. You'll have to create
round button image(s) for the round look. Take a look at the sample
code on the following site: http://mindprod.com/jgloss/jbutton.html

Here is the code that I have altered a little to make it more friendly:


public JButton someButton()
{
// Use of Images on JButtons // Create JButton object.
JButton jbutton = new JButton();

// suppress borders
jbutton.setBorderPainted ( false );

// suppress button press decoration
jbutton.setContentAreaFilled( false );

// suppress the ability of the button to be triggered by enter
jbutton.setDefaultCapable( false );

// hide focus rectangle
jbutton.setFocusPainted( false );

// set how wide the space must be around the button. Also use ipadx/ipady
jbutton.setMargin( new Insets ( 3, 3, 3, 3 ));

// ignore clicks that come too fast
jbutton.setMultiClickThreshhold( 100 /* millis */ );

// the gifs have transparent background
jbutton.setOpaque( false );

// hover help
jbutton.setToolTipText( "Launch nuclear missiles" );

// What button looks like normally.
jbutton.setIcon ( createImageIcon ( "buttonimages/frogNormal.gif" ) );

// What button looks like normally after setSelected( true ).
jbutton.setSelectedIcon ( createImageIcon
                          ( "buttonimages/frog/Normalselected.gif" ) );

// what button looks like pressed.
jbutton.setPressedIcon( createImageIcon
                        ( "buttonimages/frogPressed.gif" ) );

// what button looks like when mouse hovers over it.
jbutton.setRolloverIcon( createImageIcon
                         ( "buttonimages/frogRollover.gif" ) );

// what button looks like when mouse hovers over it after setSelected( true ).
jbutton.setRolloverSelectedIcon( createImageIcon
                                 ( "buttonimages/frogRolloverSelelected.gif" ) );

// what button looks like when it has been grayed out.
jbutton.setDisabledIcon( createImageIcon
                         ( "buttonimages/frogDisabled.gif" ) );

// what button looks like when it has been grayed out after setSelected( true ).
jbutton.setDisabledSelectedIcon( createImageIcon
                                 ( "buttonimages/frogDisabledSelected.gif" ) );

return jbutton;
}

/**
 * Read a gif or jpg from the archive jar file.
 *
 * @param gifname name of the gif in the jar.
 * @return ImageIcon corresponding to the gif/jpg.
 */
ImageIcon createImageIcon ( String gifname )
{
   try
      {
      URL url = this.getClass().getResource( gifname );
      Image image = getToolkit().createImage ( (ImageProducer) url.getContent() );
      // wait till it is loaded
      MediaTracker tracker;
      try
         {
         // wait until image is fully loaded.
         // MediaTracker arranges repaint via ImageObsever interface
         tracker = new MediaTracker( this );
         tracker.addImage( image , 0 );
         tracker.waitForID( 0 );
         }
      catch ( InterruptedException e )
         {
         }return new ImageIcon( image );
      }
   catch ( IOException e )
      {
      return null;
      }
} // end createImageIcon

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy