Wednesday, 3 August 2011

JColorChooser History

JColorChooser in java can be used to select a color from "Swatches", "HSB", "RGB" panels.  But only "Swatches" tab has a history of recent used colors. We want to have a global history for selected colors.

For that we have to add another panel in a JColorChooser (like ExcelPalette).  In java you have to create a new class which extends AbstractColorChooserPanel:
public class HistoryColorChooserPanel extends AbstractColorChooserPanel {          
         protected void buildChooser() {   
                //  here you add your UI components
To use it:
AbstractColorChooserPanel[] panels = chooser.getChooserPanels() ;
// create a new array of panels containing also your panel

Anytime a color is selected from any tab except "Color History", that color is added to history as the top-left color from the matrix, and all the other colors are moved by a cell to the right.

At first glance it does not seem a "big" functionality, but when you think you want to use a number of colors to make your reports and charts look alike, this will help you a lot of time instead of entering again and again the same colors.

1 comment:

  1. Great Article android based projects

    Java Training in Chennai

    Project Center in Chennai

    Java Training in Chennai

    projects for cse

    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training