How to Set the Background Color of a JButton on the Mac OS

前端 未结 5 1830
Happy的楠姐
Happy的楠姐 2020-11-30 08:55

Normally with Java Swing you can set the background color of a button with:

myJButton.setBackground(Color.RED);

which would cause the butto

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 08:59

    I own a mac too! here is the code that will work:

    myButton.setBackground(Color.RED);
    myButton.setOpaque(true); //Sets Button Opaque so it works
    

    before doing anything or adding any components set the look and feel so it looks better:

    try{
       UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
     }catch(Exception e){
      e.printStackTrace(); 
     }
    

    That is Supposed to change the look and feel to the cross platform look and feel, hope i helped! :)

提交回复
热议问题