How to change the button backgrounds inside JOptionPane

后端 未结 4 882
情书的邮戳
情书的邮戳 2020-12-30 17:24

I was wondering if anybody knew if it was possible to change the background color on the buttons inside a JOptionPane. I know how to change the entire JO

4条回答
  •  春和景丽
    2020-12-30 18:05

    There is no direct way to do this.

    But if you really want to give it a try, then you will need to read the JOptionPane API which gives code that shows you how to manually create and display a JOptionPane without using the showXXX methods.

    Using this approach you now have access to the actuall JDialog. Then you can use Darryl's SwingUtils to access the individual buttons and then set the background.

    The code would be something like:

    JButton ok = SwingUtils.getDescendantOfType(JButton.class, dialog, "Text", "Ok");
    ok.setBackground(...);
    

提交回复
热议问题