Java Utililty Methods JButton Settings

List of utility methods to do JButton Settings

Description

The list of methods to do JButton Settings are organized into topic(s).

Method

JButtoncreaStyledButton(int style)
Returns a styled JButton.
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));
...
AbstractButtoncustomize(AbstractButton btn)
customize
return setAllSize(btn, CUSTOM_BUTTON_DIMENSION);
TdecoratedToSimpleButton(final T button)
Set the button to have simplified UI.
button.setForeground(Color.BLACK);
button.setBackground(Color.LIGHT_GRAY);
button.setBorderPainted(true);
button.setFocusPainted(true);
button.setContentAreaFilled(false);
button.setOpaque(true);
if (button instanceof JToggleButton) {
    ((JToggleButton) button).addActionListener(new ActionListener() {
...
voiddoClick(final AbstractButton button)
Click a button, doing the click in the GUI event thread.
EventQueue.invokeAndWait(new Thread() {
    public void run() {
        button.doClick();
});
voiddoHover(boolean b, AbstractButton... btns)
do Hover
for (AbstractButton btn : btns) {
    btn.setContentAreaFilled(b);
    btn.setBorderPainted(b);
voiddoSetText(final AbstractButton abstractButton, final String text)
do Set Text
if (abstractButton != null && text != null) {
    if (SwingUtilities.isEventDispatchThread()) {
        doSetTextInEDT(abstractButton, text);
    } else {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                doSetTextInEDT(abstractButton, text);
...
voiddoSetTextInEDT(final AbstractButton abstractButton, final String text)
do Set Text In EDT
abstractButton.setText(text);
voiddrawActiveButtonBorder(Graphics g, int x, int y, int w, int h)
draw Active Button Border
drawFlush3DBorder(g, x, y, w, h);
g.setColor(MetalLookAndFeel.getPrimaryControl());
g.drawLine(x + 1, y + 1, x + 1, h - 3);
g.drawLine(x + 1, y + 1, w - 3, x + 1);
g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
g.drawLine(x + 2, h - 2, w - 2, h - 2);
g.drawLine(w - 2, y + 2, w - 2, h - 2);
voiddrawDefaultButtonBorder(Graphics g, int x, int y, int w, int h, boolean active)
draw Default Button Border
drawButtonBorder(g, x + 1, y + 1, w - 1, h - 1, active);
g.translate(x, y);
g.setColor(MetalLookAndFeel.getControlDarkShadow());
g.drawRect(0, 0, w - 3, h - 3);
g.drawLine(w - 2, 0, w - 2, 0);
g.drawLine(0, h - 2, 0, h - 2);
g.translate(-x, -y);
voidemphasizeButton(AbstractButton btn)
Try to switch the background and foreground colors.
Color col = btn.getBackground();
btn.setBackground(btn.getForeground());
btn.setForeground(col);