Java Code Examples for javax.swing.AbstractButton#setMargin()

The following examples show how to use javax.swing.AbstractButton#setMargin() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QButtonUI.java    From pumpernickel with MIT License 6 votes vote down vote up
@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));
}
 
Example 2
Source File: FlatFileChooserUI.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
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
	}
}
 
Example 3
Source File: CustomToolbar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 4
Source File: CustomToolbar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: NbEditorToolBar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 6
Source File: DataViewUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: SwingUtil.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
}
 
Example 8
Source File: RapidDockingToolbar.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@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)));
	}
}
 
Example 9
Source File: TGToolBar.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
}
 
Example 10
Source File: SearchButton.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static void processButton(AbstractButton button) {
    removeButtonContentAreaAndBorder(button);
    button.setMargin(BUTTON_INSETS);
    button.addMouseListener(sharedMouseListener);
    button.setFocusable(false);
}
 
Example 11
Source File: SeaGlassButtonUI.java    From seaglass with Apache License 2.0 4 votes vote down vote up
/**
 * 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();
}
 
Example 12
Source File: MakeLayoutPane.java    From DroidUIBuilder with Apache License 2.0 4 votes vote down vote up
private AbstractButton setToolbarBtnMargin(AbstractButton btn)
{
	btn.setMargin(new Insets(4,3,4,3));
	return btn;
}