Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom JButton with nimbus

Hello I am trying to custom the JButton from nimbus and here is what I did :

public static void main(String[] args) 
{
    // TODO Auto-generated method stub
    Font police1 = new Font("Tahoma", Font.BOLD, 12);
    try {
        for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                UIManager.setLookAndFeel(info.getClassName());
                UIManager.getLookAndFeelDefaults().put("Button.background",new Color(18,55,63));
                UIManager.getLookAndFeelDefaults().put("Button.font", police1);
                UIManager.getLookAndFeelDefaults().put("Button.textForeground", new Color(122,216,247));

                break;
            }
        }
    } catch (Exception e) {
        // If Nimbus is not available, you can set the GUI to another look    and feel.
}

And here is what I got :

buttons

As you can see there are some sort of grey border around each button and i am trying to remove it or change its color but I can't find how :( .

And once I press on one them I get this :

button pressed

And this is in fact the one wich is the more near to the Color(18,55,63) . is there a way to custom the normal look and the pressed look separatly please ? I checked this link http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/_nimbusDefaults.html but it could not help me .

like image 532
Exia0890 Avatar asked Aug 23 '26 06:08

Exia0890


1 Answers

there are some sort of grey border around each button and i am trying to remove it or change its color but I can't find how

To get rid of the JButton border simply call JButton.setBorderPainted(boolean) alternatively you can create a custom Border which meets your needs and call JButton.setBorder(Border)

like image 83
David Kroukamp Avatar answered Aug 24 '26 20:08

David Kroukamp