emphasized textI currently write Java applications on Mac OS X Mountain Lion and I want to get a button in Java which is Mac OS X style blue colored.
How do I make my button look like the Mac OS X style blue colored default button which is displayed in JOptionPane.showMessageDialog()?
I guess, you are looking for a default button.
JRootPane rootPane = SwingUtilities.getRootPane(button);
rootPane.setDefaultButton(button);

If you want to take a quick look at the result
import java.awt.*;
import javax.swing.*;
class ButtonFrame extends JFrame
{
JButton button;
ButtonFrame(String title)
{
super(title);
setLayout(new FlowLayout());
button = new JButton("OK");
add(button);
JRootPane rootPane = SwingUtilities.getRootPane(button);
rootPane.setDefaultButton(button);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
public class Sample
{
public static void main ( String[] args )
{
ButtonFrame frame = new ButtonFrame("Demo");
frame.setSize(200,80);
frame.setVisible(true);
}
}
and then
javac Sample.java
java -cp . Sample
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With