本文整理汇总了Java中javax.swing.plaf.basic.BasicRadioButtonUI类的典型用法代码示例。如果您正苦于以下问题:Java BasicRadioButtonUI类的具体用法?Java BasicRadioButtonUI怎么用?Java BasicRadioButtonUI使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BasicRadioButtonUI类属于javax.swing.plaf.basic包,在下文中一共展示了BasicRadioButtonUI类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setTextIcon
import javax.swing.plaf.basic.BasicRadioButtonUI; //导入依赖的package包/类
/**
* Sets given icon to display between checkbox icon and text.
*
* @return true in case of success and false otherwise
*/
public boolean setTextIcon(@NotNull Icon icon) {
if (UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF()) {
return false;
}
ButtonUI ui = getUI();
if (ui instanceof BasicRadioButtonUI) {
Icon defaultIcon = ((BasicRadioButtonUI) ui).getDefaultIcon();
if (defaultIcon != null) {
MergedIcon mergedIcon = new MergedIcon(defaultIcon, 10, icon);
setIcon(mergedIcon);
return true;
}
}
return false;
}
示例2: setTextIcon
import javax.swing.plaf.basic.BasicRadioButtonUI; //导入依赖的package包/类
/**
* Sets given icon to display between checkbox icon and text.
*
* @return true in case of success and false otherwise
*/
public boolean setTextIcon(@NotNull Icon icon) {
ButtonUI ui = getUI();
if (ui instanceof BasicRadioButtonUI) {
Icon defaultIcon = ((BasicRadioButtonUI) ui).getDefaultIcon();
if (defaultIcon != null) {
MergedIcon mergedIcon = new MergedIcon(defaultIcon, 10, icon);
setIcon(mergedIcon);
return true;
}
}
return false;
}
示例3: getCheckBoxDimension
import javax.swing.plaf.basic.BasicRadioButtonUI; //导入依赖的package包/类
@Nonnull
private static Dimension getCheckBoxDimension(@Nonnull JCheckBox checkBox) {
Icon icon = null;
BasicRadioButtonUI ui = ObjectUtils.tryCast(checkBox.getUI(), BasicRadioButtonUI.class);
if (ui != null) {
icon = ui.getDefaultIcon();
}
if (icon == null) {
// com.intellij.ide.ui.laf.darcula.ui.DarculaCheckBoxUI.getDefaultIcon()
icon = JBUI.scale(EmptyIcon.create(20));
}
Insets margin = checkBox.getMargin();
return new Dimension(margin.left + icon.getIconWidth(), margin.top + icon.getIconHeight());
}
示例4: setTextIcon
import javax.swing.plaf.basic.BasicRadioButtonUI; //导入依赖的package包/类
/**
* Sets given icon to display between checkbox icon and text.
*
* @return true in case of success and false otherwise
*/
public boolean setTextIcon(@Nonnull Icon icon) {
ButtonUI ui = getUI();
if (ui instanceof BasicRadioButtonUI) {
Icon defaultIcon = ((BasicRadioButtonUI) ui).getDefaultIcon();
if (defaultIcon != null) {
MergedIcon mergedIcon = new MergedIcon(defaultIcon, 10, icon);
setIcon(mergedIcon);
return true;
}
}
return false;
}
示例5: getTextRectangle
import javax.swing.plaf.basic.BasicRadioButtonUI; //导入依赖的package包/类
private static Rectangle getTextRectangle(AbstractButton button) {
String text = button.getText();
Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();
if (icon == null && button.getUI() instanceof BasicRadioButtonUI) {
icon = ((BasicRadioButtonUI)button.getUI()).getDefaultIcon();
}
if ((icon == null) && (text == null)) {
return null;
}
Rectangle paintIconR = new Rectangle();
Rectangle paintTextR = new Rectangle();
Rectangle paintViewR = new Rectangle();
Insets paintViewInsets = new Insets(0, 0, 0, 0);
paintViewInsets = button.getInsets(paintViewInsets);
paintViewR.x = paintViewInsets.left;
paintViewR.y = paintViewInsets.top;
paintViewR.width = button.getWidth() - (paintViewInsets.left + paintViewInsets.right);
paintViewR.height = button.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);
Graphics g = button.getGraphics();
if (g == null) {
return null;
}
SwingUtilities.layoutCompoundLabel(button,
g.getFontMetrics(),
text,
icon,
button.getVerticalAlignment(),
button.getHorizontalAlignment(),
button.getVerticalTextPosition(),
button.getHorizontalTextPosition(),
paintViewR,
paintIconR,
paintTextR,
button.getIconTextGap());
return paintTextR;
}
示例6: getCheckBoxTextHorizontalOffset
import javax.swing.plaf.basic.BasicRadioButtonUI; //导入依赖的package包/类
public static int getCheckBoxTextHorizontalOffset(@NotNull JCheckBox cb) {
// logic copied from javax.swing.plaf.basic.BasicRadioButtonUI.paint
ButtonUI ui = cb.getUI();
String text = cb.getText();
Icon buttonIcon = cb.getIcon();
if (buttonIcon == null && ui != null) {
if (ui instanceof BasicRadioButtonUI) {
buttonIcon = ((BasicRadioButtonUI)ui).getDefaultIcon();
}
else if (isUnderAquaLookAndFeel()) {
// inheritors of AquaButtonToggleUI
Ref<Method> cached = ourDefaultIconMethodsCache.get(ui.getClass());
if (cached == null) {
cached = Ref.create(ReflectionUtil.findMethod(Arrays.asList(ui.getClass().getMethods()), "getDefaultIcon", JComponent.class));
ourDefaultIconMethodsCache.put(ui.getClass(), cached);
if (!cached.isNull()) {
cached.get().setAccessible(true);
}
}
Method method = cached.get();
if (method != null) {
try {
buttonIcon = (Icon)method.invoke(ui, cb);
}
catch (Exception e) {
cached.set(null);
}
}
}
}
Dimension size = new Dimension();
Rectangle viewRect = new Rectangle();
Rectangle iconRect = new Rectangle();
Rectangle textRect = new Rectangle();
Insets i = cb.getInsets();
size = cb.getSize(size);
viewRect.x = i.left;
viewRect.y = i.top;
viewRect.width = size.width - (i.right + viewRect.x);
viewRect.height = size.height - (i.bottom + viewRect.y);
iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
textRect.x = textRect.y = textRect.width = textRect.height = 0;
SwingUtilities.layoutCompoundLabel(
cb, cb.getFontMetrics(cb.getFont()), text, buttonIcon,
cb.getVerticalAlignment(), cb.getHorizontalAlignment(),
cb.getVerticalTextPosition(), cb.getHorizontalTextPosition(),
viewRect, iconRect, textRect,
text == null ? 0 : cb.getIconTextGap());
return textRect.x;
}
示例7: getTextRectangle
import javax.swing.plaf.basic.BasicRadioButtonUI; //导入依赖的package包/类
private static Rectangle getTextRectangle(AbstractButton button) {
String text = button.getText();
Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();
if (icon == null && button.getUI() instanceof BasicRadioButtonUI) {
icon = ((BasicRadioButtonUI)button.getUI()).getDefaultIcon();
}
if ((icon == null) && (text == null)) {
return null;
}
Rectangle paintIconR = new Rectangle();
Rectangle paintTextR = new Rectangle();
Rectangle paintViewR = new Rectangle();
Insets paintViewInsets = new Insets(0, 0, 0, 0);
paintViewInsets = button.getInsets(paintViewInsets);
paintViewR.x = paintViewInsets.left;
paintViewR.y = paintViewInsets.top;
paintViewR.width = button.getWidth() - (paintViewInsets.left + paintViewInsets.right);
paintViewR.height = button.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);
Graphics g = button.getGraphics();
if (g == null) {
return null;
}
String clippedText =
SwingUtilities.layoutCompoundLabel(button,
g.getFontMetrics(),
text,
icon,
button.getVerticalAlignment(),
button.getHorizontalAlignment(),
button.getVerticalTextPosition(),
button.getHorizontalTextPosition(),
paintViewR,
paintIconR,
paintTextR,
button.getIconTextGap());
return paintTextR;
}