Example usage for javax.swing JButton setBorder

List of usage examples for javax.swing JButton setBorder

Introduction

In this page you can find the example usage for javax.swing JButton setBorder.

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The component's border.")
public void setBorder(Border border) 

Source Link

Document

Sets the border of this component.

Usage

From source file:BorderLayoutExample.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    JMenuBar menubar = new JMenuBar();
    JMenu file = new JMenu("File");

    menubar.add(file);// w w w.  jav  a2 s  .  co m
    f.setJMenuBar(menubar);

    JToolBar toolbar = new JToolBar();
    toolbar.setFloatable(false);

    JButton bexit = new JButton(new ImageIcon("exit.png"));
    bexit.setBorder(new EmptyBorder(0, 0, 0, 0));
    toolbar.add(bexit);

    f.add(toolbar, BorderLayout.NORTH);

    JToolBar vertical = new JToolBar(JToolBar.VERTICAL);
    vertical.setFloatable(false);
    vertical.setMargin(new Insets(10, 5, 5, 5));

    JButton selectb = new JButton(new ImageIcon("a.png"));
    selectb.setBorder(new EmptyBorder(3, 0, 3, 0));

    JButton freehandb = new JButton(new ImageIcon("b.png"));
    freehandb.setBorder(new EmptyBorder(3, 0, 3, 0));
    JButton shapeedb = new JButton(new ImageIcon("c.png"));
    shapeedb.setBorder(new EmptyBorder(3, 0, 3, 0));

    vertical.add(selectb);
    vertical.add(freehandb);
    vertical.add(shapeedb);

    f.add(vertical, BorderLayout.WEST);
    f.add(new JTextArea(), BorderLayout.CENTER);

    JLabel statusbar = new JLabel(" Statusbar");
    statusbar.setPreferredSize(new Dimension(-1, 22));
    statusbar.setBorder(LineBorder.createGrayLineBorder());
    f.add(statusbar, BorderLayout.SOUTH);
    f.setSize(350, 300);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:IconMatteBorder.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Icon Matted Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Icon diamondIcon = new DiamondIcon(Color.red, true, 10, 10);
    Border diamondBorder = new MatteBorder(10, 10, 10, 10, diamondIcon);
    JButton diamondButton = new JButton("diamonds");
    diamondButton.setBorder(diamondBorder);
    Icon diamondIcon2 = new ImageIcon("diamond.gif");
    Border diamondBorder2 = new MatteBorder(36, 40, 36, 40, diamondIcon2);
    JButton diamondButton2 = new JButton("diamonds2");
    diamondButton2.setBorder(diamondBorder2);
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(2, 1));
    contentPane.add(diamondButton);// w w w.  j  a va  2  s  .c o m
    contentPane.add(diamondButton2);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Compound Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton bevelLineButton = new JButton("Bevel Line");
    Border redBorder = BorderFactory.createLineBorder(Color.MAGENTA, 2, true);
    bevelLineButton.setBorder(redBorder);

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(1, 2));
    contentPane.add(bevelLineButton);//from   www.j a v  a  2s. c om
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:TryGridBagLayout.java

static void addButton(String label, GridBagConstraints constraints, GridBagLayout layout) {
    Border edge = BorderFactory.createRaisedBevelBorder();
    JButton button = new JButton(label);
    button.setBorder(edge);
    layout.setConstraints(button, constraints);
    aWindow.getContentPane().add(button);
}

From source file:Main.java

/**
 * Convenience method for creating buttons with an icon and no text.  Wraps
 * the button in an empty border to give it some space.
 * @param icon the icon to display/* w w w.  j  a v a 2  s . co  m*/
 * @return a new JButton with the given icon
 */
public static JButton iconButton(Icon icon) {
    final JButton result = new JButton(icon);
    result.setBorder(new EmptyBorder(4, 4, 4, 4));
    return result;
}

From source file:Main.java

/**
 * Convenience method for creating buttons with an icon and no text.  Wraps
 * the button in an empty border to give it some space.
 * @param icon the icon to display/*from   ww w  .  ja va2s. c  o m*/
 * @param action the action to perform on click
 * @return a new JButton with the given icon
 */
public static JButton iconButton(Icon icon, Action action) {
    final JButton result = new JButton(action);
    result.setIcon(icon);
    result.setBorder(new EmptyBorder(4, 4, 4, 4));
    return result;
}

From source file:Main.java

/**
 * Returns a styled JButton./*w  w  w . ja  v a2 s.  com*/
 *
 * @param style button type
 * @return a styled button
 */
public static JButton creaStyledButton(int style) {
    JButton jb = new JButton();
    jb.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    jb.setMargin(new Insets(0, 5, 1, 5));
    switch (style) {
    case STYLE_EDIT: {
        jb.setText("edit");
        jb.setToolTipText("edit");
        jb.setPreferredSize(new Dimension(60, 30));
        return jb;
    }
    case STYLE_OK: {
        jb.setText("ok");
        jb.setToolTipText("confirm changes");
        jb.setPreferredSize(new Dimension(60, 30));
        return jb;
    }
    case STYLE_CANCEL: {
        jb.setText("cancel");
        jb.setToolTipText("discard changes");
        jb.setPreferredSize(new Dimension(60, 30));
        return jb;
    }
    case STYLE_INSBEFOREROW: {
        jb.setIcon(ICON_INSBEFOREROW);
        jb.setToolTipText("insert row before");
        jb.setName("INSBEFOREROW");
        return jb;
    }
    case STYLE_INSAFTERROW: {
        jb.setIcon(ICON_INSAFTERROW);
        jb.setToolTipText("insert row after");
        jb.setName("INSAFTERROW");
        return jb;
    }
    case STYLE_DELETEROW: {
        jb.setIcon(ICON_DELETEROW);
        jb.setToolTipText("delete row");
        jb.setName("DELETEROW");
        return jb;
    }
    case STYLE_CLONEBEFOREROW: {
        jb.setIcon(ICON_CLONEBEFOREROW);
        jb.setToolTipText("clone row before");
        jb.setName("CLONEBEFOREROW");
        return jb;
    }
    case STYLE_CLONEAFTERROW: {
        jb.setIcon(ICON_CLONEAFTERROW);
        jb.setToolTipText("clone row after");
        jb.setName("CLONEAFTERROW");
        return jb;
    }
    case STYLE_DEFAULTROWS: {
        jb.setIcon(ICON_DEFAULTROWS);
        jb.setToolTipText("set default values");
        jb.setName("DEFAULTROWS");
        return jb;
    }
    default: {
        return null;
    }
    }
}

From source file:Main.java

@Override
public void updateUI() {
    super.updateUI();
    UIManager.put("ComboBox.squareButton", Boolean.FALSE);
    setUI(new BasicComboBoxUI() {
        @Override//from  w  ww  . j  a va  2s.  c o m
        protected JButton createArrowButton() {
            JButton b = new JButton();
            b.setBorder(BorderFactory.createEmptyBorder());
            b.setVisible(false);
            return b;
        }
    });
    setBorder(BorderFactory.createLineBorder(Color.GRAY));
}

From source file:Main.java

private void addButton(String label, GridBagConstraints constraints, GridBagLayout layout) {

    Border edge = BorderFactory.createRaisedBevelBorder();

    JButton button = new JButton(label);
    button.setBorder(edge);
    layout.setConstraints(button, constraints);
    add(button);//  w ww  .  ja  v  a2  s.  c  om
}

From source file:ButtonwithImageIcon.java

public ButtonPanel() {

    JButton btn = new JButton("Push Me", new BoxIcon(Color.blue, 2));
    btn.setRolloverIcon(new BoxIcon(Color.cyan, 3));
    btn.setPressedIcon(new BoxIcon(Color.yellow, 4));

    btn.setHorizontalTextPosition(JButton.LEFT);
    btn.setBorder(BorderFactory.createEtchedBorder());
    btn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Button was pressed.");
        }//from   w ww.j  a  v  a 2  s.  c  om
    });
    add(btn);
}