gpt4 book ai didi

java - JColorChooser 在 Java 中更改字体颜色

转载 作者:行者123 更新时间:2023-12-01 13:27:22 26 4
gpt4 key购买 nike

如何使用 JColorChooser 更改 java swing 中的字体颜色?

最佳答案

     import java.awt.*;
import java.awt.event.*;
import javax.swing.*;



public class JColorChooserExample extends JFrame
implements ActionListener
{


private JButton b;
private Container c;
private Color color;

public JColorChooserExample(String title)
{
super(title);

color = Color.pink;
c = getContentPane();
c.setLayout(new FlowLayout());
c.setBackground(color);

c.add(new JLabel(
"Click button to select a new background color"));
b = new JButton("Color");
b.setToolTipText("Click here to change color");
b.addActionListener(this);
c.add(b);

addWindowListener(new MyWindowCloser());
}

public void actionPerformed(ActionEvent e)
{
color = JColorChooser.showDialog(
this, "Select a Background Color", color);
if (color != null)
{
c.setBackground(color);
}
}

public static void main(String[] args)
{
JColorChooserExample jcce =
new JColorChooserExample("JColorChooser Example");
jcce.pack();
jcce.setVisible(true);
}
}

并阅读此tutorial还有

关于java - JColorChooser 在 Java 中更改字体颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21745974/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com