Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Ron McLeod
paul wheaton
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Himai Minh
Bartenders:
Forum:
Swing / AWT / SWT
Color Palette
Jenith shiva
Greenhorn
Posts: 3
posted 23 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I would like to know how to add a Color Palette on a button click to pop up and give me the R,G and B on selection of a color.
A sample code should be helpful tooo..
Thank you
Nathan Pruett
Bartender
Posts: 4121
I like...
posted 23 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The JColorChooser component has this built in... that would be the easiest thing to use... ( Select a color in it and then choose the RGB tab... )
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ColorTest extends JFrame { private JPanel p; private JButton b; private JColorChooser cc; public ColorTest() { p = new JPanel(); b = new JButton( "Show Color Chooser" ); cc = new JColorChooser(); b.addActionListener( new ColorLauncher() ); p.add( b ); getContentPane().add( p ); addWindowListener( new ExitHandler() ); setSize( 300, 300 ); setVisible( true ); } public static void main( String[] args ) { new ColorTest(); } private class ColorLauncher implements ActionListener { public void actionPerformed( ActionEvent e ) { Color newColor = JColorChooser.showDialog( cc, "Color Chooser", ColorTest.this.getBackground() ); p.setBackground( newColor ); p.repaint(); } } private class ExitHandler extends WindowAdapter { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } } }
-Nate
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Shamefully, but ....
IndexColorModel - find mapping of color pixel
Sorting a 256 color pallete......URGENT
Changing color palettes of GIF dynamically
How do I bringup a color palette with the click of a button
More...