Custom color selection panel

Source: Internet
Author: User
Import javax. Swing .*;
Import java. AWT .*;
Import java. AWT. event .*;
Import javax. Swing. colorchooser .*;//******************
Class jcolorchoosercustomtest
{
Jframe mainframe;
Jpanel mainpanel;
Jcolorchooser cc;

Public jcolorchoosercustomtest (){
Mainframe = new jframe ("jcolorchoosertest ");
Mainpanel = new jpanel (New borderlayout ());
Cc = new jcolorchooser ();

//************************************** **************************************** **************************************** ****
AbstractColorChooserPanel accps [] = {new CustomColorChooserPanel (),
New CustomColorChooserPanel ()};
Cc. setChooserPanels (accps );
//************************************** **************************************** **************************************** ****
MainPanel. add (cc );
MainFrame. add (mainPanel );
Container mainContainer = mainFrame. getContentPane ();
MainContainer. add (mainPanel, BorderLayout. PAGE_START );
MainFrame. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE );
MainFrame. pack ();
MainFrame. setVisible (true );
}
Public static void main (String [] args ){
SwingUtilities. invokeLater (new Runnable (){
Public void run (){
New JColorChooserCustomTest ();
}
});
}
}
//************************************** **************************************** *************
Class CustomColorChooserPanel extends actcolorchooserpanel implements ActionListener {

JButton redButton;
JButton greenButton;
JButton blueButton;

Public CustomColorChooserPanel (){

This. redButton = new JButton ("red ");
This. greenbutton = new jbutton ("green ");
This. bluebutton = new jbutton ("blue ");

Redbutton. addactionlistener (this );
Greenbutton. addactionlistener (this );
Bluebutton. addactionlistener (this );
}
Public void actionreceivmed (actionevent AE ){
If (jbutton) AE. getsource () = redbutton ){
GetColorSelectionModel (). setSelectedColor (Color. red );
} Else {
If (JButton) AE. getSource () = greenButton ){
GetColorSelectionModel (). setSelectedColor (Color. green );
}
Else {
GetColorSelectionModel (). setSelectedColor (Color. blue );
}
}
}
Public void buildChooser (){
Add (redButton );
Add (greenButton );
Add (blueButton );
}
Public void updateChooser (){

}
Public String getDisplayName (){
Return "CustomPanel ";
}
Public Icon getSmallDisplayIcon (){
Return null;
}

Public icon getlargedisplayicon (){
Return NULL;
}
}
//************************************** **************************************** ********************************

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.