Java JButton Settings addButtonToPanel(JPanel panel, Object constraints, String text)

Here you can find the source of addButtonToPanel(JPanel panel, Object constraints, String text)

Description

Adds a button to a panel.

License

Open Source License

Parameter

Parameter Description
panel The panel to add the button to.
constraints The constraints of the button.
text The button text.

Return

The created button.

Declaration

public static JButton addButtonToPanel(JPanel panel, Object constraints, String text) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Color;

import javax.swing.JButton;

import javax.swing.JPanel;

public class Main {
    public static final Color BACKGROUND = new Color(245, 245, 245);

    /**/*from   w  ww  .j a  va2 s .  com*/
     * Adds a button to a panel.
     * @param panel The panel to  add the button to.
     * @param constraints The constraints of the button.
     * @param text The button text.
     * @return The created button.
     */
    public static JButton addButtonToPanel(JPanel panel, Object constraints, String text) {
        JButton button = new JButton(text);
        button.setBackground(BACKGROUND);
        panel.add(button, constraints);
        return button;
    }
}

Related

  1. addActionListenerToButtons(ActionListener l, AbstractButton... components)
  2. addButton(ActionListener l, Container container, String name, String cmd)
  3. addButton(Container component, String text, Icon icon, ActionListener listener, String actionCommand)
  4. addButton(String name, JPanel panel, ActionListener action)
  5. addButtonInPanel(Container component, String text, ActionListener listener)
  6. addMiddleButtonDragSupport(Component targetComponent)
  7. addRadioButton(JPanel buttonPanel, ButtonGroup group, String buttonName, boolean selected, ActionListener listener)
  8. addToButtonGroup(ButtonGroup bg, T button)
  9. applyDefaultProperties(final Button comp)