Note that there are some explanatory texts on larger screens.

plurals
  1. POget color name of selected color in JcolorChooser
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/4126029/java-color-code-convert-to-color-name">Java color code convert to color name</a><br> <a href="https://stackoverflow.com/questions/8544585/java-swing-issue-using-color-palette">Java Swing issue - Using color palette</a> </p> </blockquote> <p>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.</p> <pre><code> 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() &amp; 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(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload