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.setDefaultCloseOperation(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 AbstractColorChooserPanel 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 actionPerformed(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 ;
}
}
// **************************************************************************************************************
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.setDefaultCloseOperation(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 AbstractColorChooserPanel 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 actionPerformed(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 ;
}
}
// **************************************************************************************************************