1
我遇到了改變我的按鈕背景顏色的問題,我剛剛開始學習如何執行GUI,並且我有以下代碼在Windows上完美工作,但我使用的是Mac OS。如何在Mac OS上更改我的按鈕顏色?
你能幫我解決嗎?
我已經添加了按鈕,然後改變了顏色,但是在運行它時,它彈出了帶有9個按鈕的窗口,但它們全都是白色的,背景是紅色的,如您所見我設置了它們在顏色藍色。
b1.setBackground(Color.BLUE);
b2.setBackground(Color.BLUE);
b3.setBackground(Color.BLUE);
b4.setBackground(Color.BLUE);
b5.setBackground(Color.BLUE);
b6.setBackground(Color.BLUE);
b7.setBackground(Color.BLUE);
b8.setBackground(Color.BLUE);
b9.setBackground(Color.BLUE);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.getContentPane().setBackground(Color.RED);
this.setBackground(Color.BLACK);
this.setVisible(true);
this.setBounds(100, 100, 800, 500);
嘗試評論'this.getContentPane()。setBackground(Color.RED);'line – 2013-09-23 15:35:28