Set Size
Set Foreground Color
Set Background Color
Set Border
Hide Border
Hide the Focus Border
Change Margin
Make Opaque
Make Invisible
Change Font
Set Gap between Icon and Text
Set Foreground Color
Set Background Color
Set Border
Hide Border
Hide the Focus Border
Change Margin
Make Opaque
Make Invisible
Change Font
Set Gap between Icon and Text
Set Size
Dimension dim = new Dimension(400, 200);
jButton1.setMinimumSize(dim);
jButton1.setPreferredSize(dim);
jButton1.getParent().revalidate();
Reset:
jButton1.setMinimumSize(null);
jButton1.setPreferredSize(null);
jButton1.getParent().revalidate();
Set Foreground Color
jButton1.setForeground(Color.RED);
Reset:
jButton1.setForeground(null);
Set Background Color
jButton1.setBackground(Color.GREEN);
Reset:
SynthStyle style = SynthLookAndFeel.getStyle(jButton1, Region.BUTTON);
SynthContext context = ((SynthButtonUI)jButton1.getUI()).getContext(jButton1);
jButton1.setBackground((Color)style.get(context, "background"));
Set Border
jButton1.setBorder(new LineBorder(Color.BLUE, 4));
Reset:
jButton1.setBorder(null);
jButton1.updateUI();
Hide Border
jButton1.setBorderPainted(false);
Reset:
jButton1.setBorderPainted(true);
Hide the Focus Border
jButton1.setFocusPainted(false);
Reset:
jButton1.setFocusPainted(true);
Change Margin
jButton1.setMargin(new Insets(20,20,20,20));
Description:
Ensures the size of the button is large enough to have this margin around the button text/icon
Reset:
jButton1.setMargin(null);
Note:
Depends on the button border if the margin will resize
Make Opaque
jButton1.setOpaque(true);
jButton1.repaint();
Reset:
jButton1.setOpaque(false);
jButton1.repaint();
Make Invisible
jButton1.setContentAreaFilled(false);
Reset:
jButton1.setContentAreaFilled(true);
Note:
Will set Opacity to true if setContentAreaFilled is set to true
Change Font
jButton1.setFont(new Font("Courier New", Font.BOLD | Font.ITALIC, 23));
Reset:
jButton1.setFont(null);
Set Gap between Icon and Text
jButton1.setIconTextGap(40);
Reset:
jButton1.setIconTextGap(4); //default value