下面列出了javax.swing.AbstractButton#setBorder ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected void installDefaults(AbstractButton b) {
super.installDefaults(b);
b.setOpaque(false);
if(!defaults_initialized) {
String pp = getPropertyPrefix();
dashedRectGapX = UIManager.getInt(pp + "dashedRectGapX");
dashedRectGapY = UIManager.getInt(pp + "dashedRectGapY");
dashedRectGapWidth = UIManager.getInt(pp + "dashedRectGapWidth");
dashedRectGapHeight = UIManager.getInt(pp + "dashedRectGapHeight");
focusColor = UIManager.getColor(pp + "focus");
defaults_initialized = true;
}
// BEXPStyle xp = BEXPStyle.getXP();
// if (xp != null)
{
b.setBorder(new XPEmptyBorder(new Insets(3,3,3,3)));//xp.getBorder(b, getXPButtonType(b)));
LookAndFeel.installProperty(b, "rolloverEnabled", Boolean.TRUE);
}
}
@Override
public void installUI(JComponent c) {
super.installUI(c);
c.setBorder(null);
if (c instanceof AbstractButton) {
AbstractButton btn = (AbstractButton) c;
btn.setBorder(new EmptyBorder(getScaledInt(5), getScaledInt(10), getScaledInt(5), getScaledInt(10)));
btn.setBorderPainted(false);
}
}
@Override
public void installUI(JComponent c) {
super.installUI(c);
if (c instanceof AbstractButton) {
AbstractButton btn = (AbstractButton) c;
// btn.setMargin(new Insets(10,10,10,10));
btn.setBorder(new EmptyBorder(getScaledInt(5), getScaledInt(10), getScaledInt(5), getScaledInt(10)));
// btn.setIcon(new XDMBlankIcon(15, 10));
btn.setBorderPainted(false);
// btn.setMargin(new Insets(10, 10, 10, 10));
// btn.setFont(new Font(Font.DIALOG, Font.PLAIN, 12));
}
}
public void installUI(JComponent c) {
super.installUI(c);
AbstractButton button = (AbstractButton)c;
button.setRolloverEnabled(true);
button.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
}
public void installUI(JComponent c) {
super.installUI(c);
AbstractButton button = (AbstractButton)c;
button.setOpaque(false);
button.setRolloverEnabled(true);
button.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
}
@Override
public void installButtonUI(AbstractButton button) {
button.setUI(new ButtonUI());
button.setBorder(null);
button.setMargin(new Insets(0, 0, 0, 0));
if ((button.getText() == null || "".equals(button.getText())) && button.getIcon() != null) {
button.setPreferredSize(new Dimension((int) (button.getIcon().getIconWidth() * 1.45d), (int) (button.getIcon()
.getIconHeight() * 1.45d)));
}
}
@Override
protected void paintButtonPressed(Graphics graphics, AbstractButton button) {
// Try to avoid switching borders if the button has none, or custom
// borders
if (style.getBorder().equals(button.getBorder())) {
button.setBorder(style.getBorderDown());
}
}
public void installUI(JComponent c) {
super.installUI(c);
AbstractButton button = (AbstractButton)c;
button.setRolloverEnabled(true);
button.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
}
/** Install a border on the button */
protected void installBorder (AbstractButton b) {
b.setBorder (BorderFactory.createEtchedBorder());
}
@Override
protected void installBorder (AbstractButton b) {
b.setBorder (BorderFactory.createEmptyBorder (5,2,2,2));
}
/**
* Allocate and dress an instance of the provided class, then register the action in
* the UI structure (menus and buttons) according to the action descriptor parameters.
*
* @param action the provided action class
* @return the registered and decorated instance of the action class
*/
@SuppressWarnings("unchecked")
private ApplicationAction registerAction (ActionDescriptor desc)
{
///logger.info("registerAction. " + desc);
ApplicationAction action = null;
try {
// Retrieve proper class instance
Class<?> classe = classLoader.loadClass(desc.className);
Object instance = null;
// Reuse existing instance through a 'getInstance()' method if any
try {
Method getInstance = classe.getDeclaredMethod("getInstance", (Class[]) null);
if (Modifier.isStatic(getInstance.getModifiers())) {
instance = getInstance.invoke(null);
}
} catch (NoSuchMethodException ignored) {
}
if (instance == null) {
// Fall back to allocate a new class instance
instance = classe.newInstance();
}
// Retrieve the action instance
action = getActionInstance(instance, desc.methodName);
if (action != null) {
// Insertion of a button on Tool Bar?
if (desc.buttonClassName != null) {
Class buttonClass = classLoader.loadClass(desc.buttonClassName);
AbstractButton button = (AbstractButton) buttonClass.newInstance();
button.setAction(action);
toolBar.add(button);
button.setBorder(UIUtil.getToolBorder());
button.setText("");
}
} else {
logger.error("Unknown action {} in class {}", desc.methodName, desc.className);
}
} catch (ClassNotFoundException |
IllegalAccessException |
IllegalArgumentException |
InstantiationException |
SecurityException |
InvocationTargetException ex) {
logger.warn("Error while registering " + desc, ex);
}
return action;
}
private static void setButtonProperties(AbstractButton button) {
button.setBorder(new RoundedBorder(5));
button.setForeground(ColorPalette.FOREGROUND_COLOR);
button.setFont(Fonts.FONT);
}
/**
* Allocate and dress an instance of the provided class, then
* register the action in the UI structure (menus and buttons)
* according to the action descriptor parameters.
*
* @param action the provided action class
* @return the registered and decorated instance of the action class
*/
@SuppressWarnings("unchecked")
private ApplicationAction registerAction (ActionDescriptor desc)
{
///logger.info("registerAction. " + desc);
ApplicationAction action = null;
try {
// Retrieve proper class instance
Class<?> classe = classLoader.loadClass(desc.className);
Object instance = null;
// Reuse existing instance through a 'getInstance()' method if any
try {
Method getInstance = classe.getDeclaredMethod(
"getInstance",
(Class[]) null);
if (Modifier.isStatic(getInstance.getModifiers())) {
instance = getInstance.invoke(null);
}
} catch (NoSuchMethodException ignored) {
}
if (instance == null) {
// Fall back to allocate a new class instance
///logger.warn("instantiating instance of " + classe);
instance = classe.newInstance();
}
// Retrieve the action instance
action = getActionInstance(instance, desc.methodName);
if (action != null) {
// Insertion of a button on Tool Bar?
if (desc.buttonClassName != null) {
Class<? extends AbstractButton> buttonClass =
(Class<? extends AbstractButton>) classLoader.
loadClass(desc.buttonClassName);
AbstractButton button = buttonClass.newInstance();
button.setAction(action);
toolBar.add(button);
button.setBorder(UIUtil.getToolBorder());
button.setText("");
}
} else {
logger.error("Unknown action {} in class {}",
desc.methodName, desc.className);
}
} catch (ClassNotFoundException | SecurityException |
IllegalAccessException | IllegalArgumentException |
InvocationTargetException | InstantiationException ex) {
logger.warn("Error while registering " + desc, ex);
}
return action;
}
private void initialiseToolBarButton(AbstractButton button) {
button.addActionListener(this);
button.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
}
public static void initialiseButton(AbstractButton button, boolean leftBorder, boolean rightBorder){
button.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(0,leftBorder?1:0,0,rightBorder?1:0,Color.LIGHT_GRAY),
BorderFactory.createEmptyBorder(4,4,4,4)));
}