Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2008

Tip: Looking for answers? Try searching our database.

Size of a radiobutton

Thread view: 
Andre Rothe - 23 Apr 2008 10:14 GMT
Hi,

Is there a possibility to get the size of a radio button? You can use
getWidth() and getHeight() of a JRadioButton, but this comes from the
component, which will be resized depending on the layout you use. I need
the size of the clickable unchangable circle (which size depends on the
look and feel).

Thanx
Andre
Frank Meyer - 23 Apr 2008 15:47 GMT
> the size of the clickable unchangable circle

Hi Andre,
this is the radiobutton-icon.
Below is a code-snippet.
Hope this helps
Frank

import javax.swing.*;

public class ButtonIconResolver {
 /**
  * extracted from BasicRadioButtonUI
  * @param b
  * @return
  */
 public static Icon getIcon(JRadioButton b) {
  ButtonModel model = b.getModel();
  Icon icon = b.getIcon();
  if (icon != null) {
   if (!model.isEnabled()) {
    if (model.isSelected()) {
     icon = b.getDisabledSelectedIcon();
    } else {
     icon = b.getDisabledIcon();
    }
   } else if (model.isPressed() && model.isArmed()) {
    icon = b.getPressedIcon();
    if (icon == null) {
     icon = b.getSelectedIcon();
    }
   } else if (model.isSelected()) {
    if (b.isRolloverEnabled() && model.isRollover()) {
     icon = b.getRolloverSelectedIcon();
     if (icon == null) {
      icon = b.getSelectedIcon();
     }
    } else {
     icon = b.getSelectedIcon();
    }
   } else if (b.isRolloverEnabled() && model.isRollover()) {
    icon = b.getRolloverIcon();
   }
   if (icon == null) {
    icon = b.getIcon();
   }
   return icon;
  } else {
   return UIManager.getIcon("RadioButton.icon");
  }
 }
}
Andre Rothe - 25 Apr 2008 15:41 GMT
Hi Frank,

Thank you very much, it works! I had used a proximity of 10 px for the
radius, but it haven't worked for all tested L&F. With your snipped I
can get the radius from the icon width.

Thanks!
Andre

>> the size of the clickable unchangable circle
>
[quoted text clipped - 3 lines]
> Hope this helps
> Frank
Thomas A. Russ - 25 Apr 2008 16:49 GMT
> Hi,
>
[quoted text clipped - 3 lines]
> the size of the clickable unchangable circle (which size depends on the
> look and feel).

But why do you want to get that?

Remember that, the native behavior (for example, on the Mac and Windows)
of check boxes and radio buttons is that they are active if the icon OR
the text label is clicked.  This behavior is, of course, highly useful
for user productivity, since it gives a much larger target to hit with
the mouse button.  (See Fitt's law, e.g.,
<http://en.wikipedia.org/wiki/Fitts'_law>,
<http://www.asktog.com/basics/firstPrinciples.html>)

Mac users, in particular, would tend to notice that the behavior isn't
quite what they expected.  But I suppose that this

Signature

Thomas A. Russ,  USC/Information Sciences Institute

Andre Rothe - 26 Apr 2008 10:26 GMT
Hi Thomas,

I would like to paint some extra shapes in the panel with the radio
buttons, so I need to know, where are the borders of the button. I don't
show the label of the button, so I only have to know, how large is the
button to paint around it.

Thank you.
Andre

> But why do you want to get that?
Thomas A. Russ - 28 Apr 2008 22:46 GMT
> Hi Thomas,
>
> I would like to paint some extra shapes in the panel with the radio
> buttons, so I need to know, where are the borders of the button. I don't
> show the label of the button, so I only have to know, how large is the
> button to paint around it.

Hmmm.  If the images for the button graphics are opaque, wouldn't it be
easier to just paint your additional shapes on the background first, and
then have the normal painting occur?  Or do you have to tailor your
shapes to the existing button image?

> Thank you.
> Andre
>
> > But why do you want to get that?

Signature

Thomas A. Russ,  USC/Information Sciences Institute



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.