There will come a time when you want only a selected tab to appear in the JColorChooser. As far as I know, there is no way to do this with Java‘s API. If there is, please leave a comment and share.

Here is an initial code that I found in Example Depot that removes the tabs:

Just comment out the lines that call removeChooserPanel() method if you do not want those tabs to be removed.

There is no direct way to do this based on the JColorChooser API so we will have to do it old style.

The getComponent(0) refers to the first tab of the JColorChooser, in this case the swatch tab. The remove() method is called twice on index number 1 and 2 because 1 is the JLabel while 2 is the recent color history.

That’s it. That should give you a swatch content only tab.

Related Posts Plugin for WordPress, Blogger...