Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i am working with JFrame. In design View i put One JBUtton , two JTextField and swing windows JColorChooser. than i write a code for this getting hex value and color name in a two JTextField.the process is if i click on JButton, it will open JColorChooser palette, After that i click on JColorChooser for select a color it show corresponding color hex value in one JtextField and color Name in another JTextField. but i can get hex value but i don't know how i can get color name.

  import javax.swing.*;
        import java.awt.*;
      import javax.swing.event.*;
       import java.util.Set;
       import javax.accessibility.*;
        import javax.swing.colorchooser.ColorSelectionModel;7.
      public class Main extends JComponent implements Accessible
      {
         public ColorSelectionModel selectionModel;
         public static  final String SELECTION_MODEL_PROPERTY = "selectionModel";
         public  JColorChooser chooser;
         public Color color;
         public void process()
         {
         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) {
             color = chooser.showDialog(chooser, "SHOW THE COLOR", chooser.getColor());
            {
              if(color!= null)
               {
                 String hex = Integer.toHexString(color.getRGB() & 0xffffff);
                 hex="#"+hex;
                 text1.setText(hex);
               }
             }
       }
             });
         frame.setVisible(true);
         frame.setSize(1000,800);
         }
        public static void main( String [] argv)
       {
         Main m1 = new Main();
       m1.process();
      }
    }
    </pre></code>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
187 views
Welcome To Ask or Share your Answers For Others

1 Answer

Most colors don't have something like a name. Your mapping would only work from the other side.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...