Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: JColorChooser won't change text color of JLabel

  1. #1
    Join Date
    Oct 2011
    My Mood
    Thanked 0 Times in 0 Posts

    Cool JColorChooser won't change text color of JLabel

    I'm trying to create a JColorChooser dialog box with a JLabel above it, so that the JLabel text color will change to the color chosen with JColorChooser by the user. Here's what I have so far, but it is not compiling for me. I am getting the following error:

    JColorChooserExample.java:22: cannot find symbol
    symbol : method addChangeListener(JColorChooserExample.ListenerCla ss)
    location: class javax.swing.JColorChooser
    1 error

    import javax.swing.*;
    import java.awt.*;
    import javax.swing.event.*;
    public class JColorChooserExample extends JFrame
    	private JColorChooser colorChooser;						           // instance variables		  
    	private JLabel banner;
    	public JColorChooserExample()											  // constructor
    		add(banner = new JLabel("Welcome to the Tutorial Zone!", JLabel.CENTER), BorderLayout.NORTH);
    		add(colorChooser = new JColorChooser(banner.getForeground()), BorderLayout.SOUTH);
    		ListenerClass listener = new ListenerClass();
    	public static void main(String[] args)
    		JColorChooserExample frame = new JColorChooserExample();   // new frame object 
    		frame.setTitle("JColorChooser Example");                   // set frame title
    		frame.pack();															  // sizes the frame so components fit frame  
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);      // ends program on frame closing
    		frame.setLocationRelativeTo(null);								  // centre frame
    		frame.setVisible(true);                                    // make frame visible
    	private class ListenerClass implements ChangeListener
    		public void stateChanged(ChangeEvent e) 
        		Color newColor = colorChooser.getColor();

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,445 Times in 2,396 Posts

    Default Re: JColorChooser won't change text color of JLabel

    Where is the addChangeListener() method defined?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Can't get JLabel to change text while program is running.
    By jollex5 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 27th, 2013, 09:08 AM
  2. How do we give a color to a disabled url label which extends a jlabel
    By oberoi06 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 16th, 2013, 11:15 AM
  3. Loop through JLabel and change JLabel
    By JoeBrown in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 11th, 2012, 12:52 PM
  4. text color changer based on words/ word classification by color
    By knoxy5467 in forum Java Theory & Questions
    Replies: 25
    Last Post: June 15th, 2011, 07:52 AM
  5. Change of color for selected text in AWT
    By venkyInd in forum AWT / Java Swing
    Replies: 2
    Last Post: April 9th, 2010, 03:51 AM

Tags for this Thread