I have a task to finish from an assignment that I am working on. And I need a little help. I need to choose a color from the JColorChooser. Then, the JLable that I have near (that initially says "No color selected") should change the text into "This is your color" and that text should be the same color as the one choosen from the JColorChooser. The problem is, when I run the program, the text changes after I select the color from the color chooser, but the color of the changed text doesn't change. It is white.This is what I got so far:
private void colorActionPerformed(java.awt.event.ActionEvent evt) {
JColorChooser jcc = new JColorChooser ();
jcc.showDialog(null, "Choose your color", Color.GREEN);
Color c = jcc.getColor();
jLabel2.setText("This is your color");
jLabel2.setForeground(c);
Don't use Color c = jcc.getColor();
Instead, use
Color c = jcc.showDialog(null, "Choose your color", Color.GREEN);
Only use getColor() after that if the returned value of c is null.