下面列出了javax.swing.AbstractButton#setMargin ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void installUI(JComponent c) {
super.installUI(c);
AbstractButton button = (AbstractButton) c;
ButtonInfo i = getButtonInfo(button, true);
button.getModel().addChangeListener(i.buttonStateListener);
button.addPropertyChangeListener(PROPERTY_BOOLEAN_BUTTON_STATE,
i.booleanStateListener);
button.addPropertyChangeListener(PROPERTY_HORIZONTAL_POSITION,
i.refreshBorderListener);
button.addPropertyChangeListener(PROPERTY_VERTICAL_POSITION,
i.refreshBorderListener);
button.addPropertyChangeListener(PROPERTY_STROKE_PAINTED,
i.refreshBorderListener);
button.addPropertyChangeListener(PROPERTY_IS_CIRCLE,
i.refreshBorderListener);
button.addKeyListener(focusArrowListener);
button.setRolloverEnabled(true);
buttons.add(button);
button.setOpaque(false);
button.setMargin(new Insets(0,4,0,4));
}
private void patchUI( JFileChooser fc ) {
// turn top-right buttons into toolbar buttons
Component topPanel = fc.getComponent( 0 );
if( (topPanel instanceof JPanel) &&
(((JPanel)topPanel).getLayout() instanceof BorderLayout) )
{
Component topButtonPanel = ((JPanel)topPanel).getComponent( 0 );
if( (topButtonPanel instanceof JPanel) &&
(((JPanel)topButtonPanel).getLayout() instanceof BoxLayout) )
{
Insets margin = UIManager.getInsets( "Button.margin" );
Component[] comps = ((JPanel)topButtonPanel).getComponents();
for( int i = comps.length - 1; i >= 0; i-- ) {
Component c = comps[i];
if( c instanceof JButton || c instanceof JToggleButton ) {
AbstractButton b = (AbstractButton)c;
b.putClientProperty( FlatClientProperties.BUTTON_TYPE,
FlatClientProperties.BUTTON_TYPE_TOOLBAR_BUTTON );
b.setMargin( margin );
b.setFocusable( false );
} else if( c instanceof Box.Filler )
((JPanel)topButtonPanel).remove( i );
}
}
}
// increase maximum row count of directory combo box popup list
try {
Component directoryComboBox = ((JPanel)topPanel).getComponent( 2 );
if( directoryComboBox instanceof JComboBox ) {
int maximumRowCount = UIManager.getInt( "ComboBox.maximumRowCount" );
if( maximumRowCount > 0 )
((JComboBox<?>)directoryComboBox).setMaximumRowCount( maximumRowCount );
}
} catch( ArrayIndexOutOfBoundsException ex ) {
// ignore
}
}
public void addButton(AbstractButton button) {
Icon icon = button.getIcon();
Dimension size = new Dimension(icon.getIconWidth() + 6, icon.getIconHeight() + 10);
button.setMinimumSize(size);
button.setPreferredSize(size);
button.setMaximumSize(size);
button.setMargin(new Insets(5, 4, 5, 4));
toolbar.add(button);
}
public void addButton(AbstractButton button) {
Icon icon = button.getIcon();
Dimension size = new Dimension(icon.getIconWidth() + 6, icon.getIconHeight() + 10);
button.setPreferredSize(size);
button.setMargin(new Insets(5, 4, 5, 4));
toolbar.add(button);
}
private void processButton(AbstractButton button) {
removeButtonContentAreaAndBorder(button);
button.setMargin(BUTTON_INSETS);
if (button instanceof AbstractButton) {
button.addMouseListener(sharedMouseListener);
}
//fix of issue #69642. Focus shouldn't stay in toolbar
button.setFocusable(false);
}
private void processButton(AbstractButton button) {
button.setContentAreaFilled(false);
button.setBorderPainted(false);
button.setMargin(BUTTON_INSETS);
if (button instanceof AbstractButton) {
button.addMouseListener(sharedMouseListener);
}
//Focus shouldn't stay in toolbar
button.setFocusable(false);
}
public static void removeButtonDecorations(AbstractButton button)
{
button.setBorderPainted(false);
button.setContentAreaFilled(false);
button.setFocusPainted(false);
button.setMargin(new Insets(0, 0, 0, 0));
button.setOpaque(false);
}
@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)));
}
}
private AbstractButton getImageButton( AbstractButton button, String iconPrefix, String iconSuffix ){
button.setHorizontalTextPosition(JButton.CENTER);
button.setVerticalTextPosition(JButton.CENTER);
button.setBorderPainted( false );
button.setContentAreaFilled( false );
button.setFocusPainted( false );
button.setMargin( new Insets(0,0,0,0) );
button.setIcon( TGResourceUtils.loadIcon( iconPrefix + iconSuffix ) );
button.setPressedIcon( TGResourceUtils.loadIcon( iconPrefix + "_pressed" + iconSuffix ) );
button.setRolloverIcon( TGResourceUtils.loadIcon( iconPrefix + "_over" + iconSuffix ) );
button.setSelectedIcon( TGResourceUtils.loadIcon( iconPrefix + "_selected" + iconSuffix ) );
button.setRolloverSelectedIcon( TGResourceUtils.loadIcon( iconPrefix + "_selected_over" + iconSuffix ) );
return button;
}
private static void processButton(AbstractButton button) {
removeButtonContentAreaAndBorder(button);
button.setMargin(BUTTON_INSETS);
button.addMouseListener(sharedMouseListener);
button.setFocusable(false);
}
/**
* Update the style of the button.
*
* @param b the button.
*/
public void updateStyle(AbstractButton b) {
SeaGlassContext context = getContext(b, SynthConstants.ENABLED);
SynthStyle oldStyle = style;
style = SeaGlassLookAndFeel.updateStyle(context, this);
if (style != oldStyle) {
if (b.getMargin() == null || (b.getMargin() instanceof UIResource)) {
Insets margin = (Insets) style.get(context, getPropertyPrefix() + "margin");
if (margin == null) {
// Some places assume margins are non-null.
margin = SeaGlassLookAndFeel.EMPTY_UIRESOURCE_INSETS;
}
b.setMargin(margin);
}
Object value = style.get(context, getPropertyPrefix() + "iconTextGap");
if (value != null) {
LookAndFeel.installProperty(b, "iconTextGap", value);
}
value = style.get(context, getPropertyPrefix() + "contentAreaFilled");
LookAndFeel.installProperty(b, "contentAreaFilled", value != null ? value : Boolean.TRUE);
value = b.getClientProperty(APPLE_PREFIX + "buttonType");
if (value != null) {
if ("segmented".equals(value)) {
b.setMargin(SeaGlassLookAndFeel.EMPTY_UIRESOURCE_INSETS);
}
}
if (oldStyle != null) {
uninstallKeyboardActions(b);
installKeyboardActions(b);
}
}
context.dispose();
}
private AbstractButton setToolbarBtnMargin(AbstractButton btn)
{
btn.setMargin(new Insets(4,3,4,3));
return btn;
}