简简单单的一个颜色选择版,
首先看下测试界面:
当我们在点击JButton按钮时,运行结果:
然后分享下我自己的源代码:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TestChooseColor extends JFrame {
public static void main(String[] args) {
TestChooseColor testChooseColor = new TestChooseColor();
testChooseColor.setTitle("TestJChooseColor");
JPanel jPanel = new JPanel();
JButton jButton = new JButton("chooseColor");
jButton.setPreferredSize(new Dimension(600, 80));
jButton.addActionListener(e -> {
JColorChooser colorDialog = new JColorChooser();
JColorChooser.createDialog(testChooseColor, "Choose Color", true, colorDialog, new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
}, new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
Color fontColor = JColorChooser.showDialog(testChooseColor, "Choose Color", Color.red);
});
jPanel.add(jButton);
testChooseColor.add(jPanel);
testChooseColor.setVisible(true);
testChooseColor.setSize(600, 600);
testChooseColor.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}