[英]How to change font size/color of a button in java?
JFrame f = new JFrame("ia");
f.setSize(1000, 500);
f.setLocation(300,100);
JTextArea textArea = new JTextArea(10, 40);
f.getContentPane().add(BorderLayout.CENTER, textArea);
JButton button = new JButton("START");
//button.setFont(new Font("Comic Sans MS", Font.PLAIN, 20));
//button.setBackgroundColor(Color.BLUE);
f.getContentPane().add(BorderLayout.CENTER, button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
textArea.append("Button was clicked\n");
The comment areas is what I have tried;评论区是我尝试过的; the program works otherwise when I run it.
当我运行它时,程序会以其他方式运行。 I took out all the import/bracket mumbo jumbo to save space.
我取出了所有导入/支架 mumbo jumbo 以节省空间。
Did you try this?你试过这个吗?
JButton b = new JButton("Test");
b.setFont(new Font("arial", Font.BOLD, 14));
b.setForeground(Color.blue);
b.setBackground(Color.red);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.