3

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 .

Exia0890
  • 441
  • 6
  • 21

2 Answers2

5

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)

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
David Kroukamp
  • 36,155
  • 13
  • 81
  • 138
  • 1
    Thanks for your answers, but unfortunately the Button.setBorderPainted(false); did not change anything, it may not work for nimbus button. :( – Exia0890 Dec 18 '12 at 12:15
  • @Exia0890 have look at XxxPainters for Button, another way could be use one on Nimbus defaults, but will be concuring with another JComponents too, question only Borders around JButton is issue ??? – mKorbel Dec 18 '12 at 15:53
  • Yup I see so. Urgh Nimbus..I am still looking for some possibilities before deciding to delete this post as entirely not relevant to question – David Kroukamp Dec 18 '12 at 15:53
0

I don't know about "XxxPainters" But, there is a solution for the border here With Nimbus, make control background color yellow only when control has focus? And here I found some useful tips to recreate a button : Creating a custom button in Java with JButton .

Community
  • 1
  • 1
Exia0890
  • 441
  • 6
  • 21