0

Possible Duplicate:
Java color code convert to color name
Java Swing issue - Using color palette

i created a program for to display color name and hexadecimal value for the selected color from Jcolorchooser, i got an output for when i select a color from the Jcolorchooser it will display hexa decimal value in a JTextField. Now i don't know how to get color name of that selected color in JTextField. kindly help me out from this problem.

   Enter code here
    ===============
    import javax.swing.*;
    import javax.swing.JButton .*;
    import javax.swing.JColorChooser .*;
    import javax.swing.JTextField .*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.Color;
    import javax.accessibility.*;

 public class Main extends JComponent implements Accessible
{

      public  JColorChooser chooser;
      public Color color;


   public Main()
     {

     JFrame frame;

     JButton  button ;

     final JTextField text1,text2;
     chooser = new JColorChooser();

     frame= new JFrame();
     JPanel panel = new JPanel();
     button = new JButton("Show color Palette");

     text1 = new JTextField(20);
     text2 = new JTextField(20);

     frame.add(panel);
     panel.add(button);
     panel.add(text1);
     panel.add(text2);
     panel.add(chooser);
     chooser.setVisible(false);
     button.setLocation(800,600);
     button.setActionCommand("");
     button.addActionListener(new ActionListener() {

                  public void actionPerformed(ActionEvent ae) {
                      //chooser.setVisible(true);
                      color = chooser.showDialog(chooser, "SHOW THE COLOR", chooser.getColor());
                      {
                          if(color!= null)
                          {
                              String hex = Integer.toHexString(color.getRGB() & 0xffffff);
                                //hex= hex.substring(2,hex.length());
                                hex="#"+hex;
                                text1.setText(hex);

                          }

         }
  }

         }

           );



     frame.setVisible(true);
     frame.setSize(1000,800);
     }

public static void main( String [] argv)
{
      new Main();
 }
}
Community
  • 1
  • 1
Ayesha
  • 25
  • 1
  • 2
  • 5
  • can you elaborate on "color name"? If you have an example (with a hex value), clearly describe what you want to do with that example color. – JustBeingHelpful Dec 19 '11 at 06:16
  • Do you know name of all colors? of should I say "Does all colors has a name?" – Harry Joy Dec 19 '11 at 06:18
  • Not all colour combinations have a name associated with them. Anyway, these two questions are similar to yours: [Java color code convert to color name](http://stackoverflow.com/questions/4126029/java-color-code-convert-to-color-name), [How to get name of color using Color Chooser in java](http://stackoverflow.com/questions/1654582/how-to-get-name-of-color-using-color-chooser-in-java). – AusCBloke Dec 19 '11 at 06:19
  • 1
    You may be able to use [Java Swing issue - Using color palette](http://stackoverflow.com/questions/8544585/java-swing-issue-using-color-palette). – trashgod Dec 19 '11 at 06:37

0 Answers0