Colors 为什么我的按钮文本的颜色不变?
框。设置前景(颜色。蓝色); frame.add(新的JButton(“蓝色”))Colors 为什么我的按钮文本的颜色不变?,colors,jbutton,Colors,Jbutton,框。设置前景(颜色。蓝色); frame.add(新的JButton(“蓝色”)) 当我运行它时,文本保持黑色?除非按钮的名称是frame,否则它当然不工作。您将边框设置为蓝色,但按钮的颜色保持不变。您的代码应该如下所示: JFrame frame = new JFrame(); add(frame, BorderLayout.CENTER); JButton button = new JButton("blue"); // button.setBackground(Co
当我运行它时,文本保持黑色?除非按钮的名称是frame,否则它当然不工作。您将边框设置为蓝色,但按钮的颜色保持不变。您的代码应该如下所示:
JFrame frame = new JFrame();
add(frame, BorderLayout.CENTER);
JButton button = new JButton("blue");
// button.setBackground(Color.CYAN);
button.setForeground(Color.BLUE);
frame.add(button);
它使回答您的问题变得更容易您似乎对JButtons不熟悉,因此请访问此网站——它解释了JButtons的使用,并解释了
ActionListener
以及ActionPerformed