Demonstrates the use of a JColorChooser which presents a dialog with three different tabbed panes to allow the user to select a color preference. The dialog returns a Color object based on the user's selection or null if the user entered Cancel. import java.awt.*; import java.awt.event.*; import javax.swing.*; /** Simple example illustrating the use of JColorChooser. * * . */ public class JColorChooserTest extends JFrame implements ActionListener { public static void main(String[] args) { new JColorChooserTest(); } public JColorChooserTest() { super("Using JColorChooser"); WindowUtilities.setNativeLookAndFeel(); addWindowListener(new ExitListener()); Container content = getContentPane(); content.setBackground(Color.white); content.setLayout(new FlowLayout()); JButton colorButton = new JButton("Choose Background Color"); colorButton.addActionListener(this); content.add(colorButton); setSize(300, 100); setVisible(true); } public void actionPerformed(ActionEvent e) { // Args are parent component, title, initial color. Color bgColor = JColorChooser.showDialog(this, "Choose Background Color", getBackground()); if (bgColor != null) getContentPane().setBackground(bgColor); } }
Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10310
Categories:Programming Code Examples, Java/J2EE/J2ME, Basic Swing
Tags:Java/J2EE/J2MEBasic Swing
Post Data:2017-01-02 16:04:31
Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada