title: ColorChooser by clicking JMenu Item
body: <p>I tried codes from different site's and one from here about a color. How do I get color chooser to work with the press of a jmenu item?</p>
  
  <p>I looked at <a href="http://java.about.com/od/UsingDialogBoxes/ss/Color-Chooser-Program.htm" rel="nofollow">ColorChooser Example</a> and also <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/colorchooser.html" rel="nofollow">Oracle Color Chooser Example</a> and then implementing into the original class using the following code:</p>
  
  <pre><code>   JMenuItem clr = new JMenuItem("Font Color");
      clr.addActionListener(new ActionListener(){
  
          public void actionPerformed(ActionEvent e)
          {
              ColorChooserDemo ccd = new ColorChooserDemo();
              ccd.setVisible(true);
          }
      });
  </code></pre>
  
  <p>But this seems do do nothing when I press the menu item.</p>
  
  <p>The class code is from the oracle webpage. These are the following class I use (shortened of course to the problem at hand). I'm making a notepad program as i'm getting back into programming and refreshing my memory of how to do things in java. Problem at hand is, I am unable to get the color chooser to come up when I click on the jmenuitem clr (which is font color) the following code show's what I have so far:</p>
  
  <p>Color Chooser Class:</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  import javax.swing.event.*;
  import javax.swing.colorchooser.*;
  
  /* ColorChooserDemo.java requires no other files. */
  @SuppressWarnings("serial")
  public class ColorChooserDemo extends JPanel
                                implements ChangeListener {
  
      protected JColorChooser tcc;
      protected JLabel banner;
  
      public ColorChooserDemo() {
          super(new BorderLayout());
  
          //Set up color chooser for setting text color
          tcc = new JColorChooser();
          tcc.getSelectionModel().addChangeListener(this);
          tcc.setBorder(BorderFactory.createTitledBorder(
                                               "Choose Text Color"));
  
          add(tcc, BorderLayout.PAGE_END);
      }
  
      public void stateChanged(ChangeEvent e) {
          Color newColor = tcc.getColor();
          FirstWindow.ta1.setForeground(newColor);
      }
  
      /**
       * Create the GUI and show it.  For thread safety,
       * this method should be invoked from the
       * event-dispatching thread.
       */
      private static void createAndShowGUI() {
          //Create and set up the window.
          JFrame frame = new JFrame("ColorChooserDemo");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
          //Create and set up the content pane.
          JComponent newContentPane = new ColorChooserDemo();
          newContentPane.setOpaque(true); //content panes must be opaque
          frame.setContentPane(newContentPane);
  
          //Display the window.
          frame.pack();
          frame.setVisible(true);
      }
  
      public static void main(String[] args) {
          //Schedule a job for the event-dispatching thread:
          //creating and showing this application's GUI.
          javax.swing.SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                  createAndShowGUI();
              }
          });
      }
  }
  </code></pre>
  
  <p>Main Class:</p>
  
  <p>import java.awt.EventQueue;</p>
  
  <pre><code>public class Main{
      protected static Object fw;
  
      public static void main(String[] args)
      {
          EventQueue.invokeLater(new Runnable(){
  
              @Override
              public void run() {
                  // TODO Auto-generated method stub
                  try
                  {
                      FirstWindow fw = new FirstWindow();
                      fw.setVisible(true);
                  } catch (Exception e)
                  {
                      e.printStackTrace();
                  }
  
              }
  
          });
      }
  }
  </code></pre>
  
  <p>FirstWindow class:</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  import java.io.*;
  
  
  public class FirstWindow extends JFrame {
      private static final long serialVersionUID = 1L;
      protected JColorChooser tcc;
      protected static JTextArea ta1;
  
      public FirstWindow() {
          super("Note Pad");
  
          Font font = new Font("Verdana", Font.BOLD, 12);
  
          //Setting the size of the note pad
          setSize(650, 745);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
  
          //Create the MenuBar
          JMenuBar mb = new JMenuBar();
          setJMenuBar(mb);
  
          //Create the panel to hold everything in
          JPanel p = new JPanel();
  
          //Create the Text Area
          final JTextArea ta1 = new JTextArea();
          ta1.setFont(font);
          ta1.setMargin(new Insets(5,5,5,5));
          ta1.setLineWrap(true);
          ta1.setWrapStyleWord(true);
  
          //Create the Scroll Pane to hold the Text Area 
          final JScrollPane sp = new JScrollPane(ta1);
          sp.setPreferredSize(new Dimension(625,675));
          sp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
  
          //Create the menu's
          JMenu format = new JMenu("Format");
  
              //Create menu item for picking font color
          JMenuItem clr = new JMenuItem("Font Color");
          clr.addActionListener(new ActionListener(){
  
              public void actionPerformed(ActionEvent e)
              {
                  ColorChooserDemo ccd = new ColorChooserDemo();
                  ccd.setVisible(true);
              }
          });
  
          //adding the menu items to the file menu tab
  
          //adding menu items to the edit tab
  
          //adding menu items to the format tab
          format.add(clr);
  
          //adding the menus to the menu bar
          mb.add(format);
  
  
          //adding the scroll pane to the panel
          p.add(sp);
          add(p, BorderLayout.CENTER);
  
      }
  }
  </code></pre>