Code Monkey home page Code Monkey logo

colorpicker's Introduction

🎨 Java Swing Color Picker Dialog

Maven Central Java CI with Maven ko-fi

A nice color picker using Java Swing that contains a visual color selection and input boxes to enter RGB and HSB values manually:

  • Two color modes HSV and RGB
  • Includes an alpha selection
  • Determine color by hex code
  • Allows to select color by clicking on color wheel
  • Minimal dependencies (only SLF4J)
  • Compatible with Java versions since version 8
  • Well documented
  • Easy to use
  • Completely free and open source

Screenshot of color picker

🔧 Usage

Include the following dependency to your project:

<dependency>
  <groupId>org.drjekyll</groupId>
  <artifactId>colorpicker</artifactId>
  <version>2.0.1</version>
</dependency>

Use the class com.bric.colorpicker.ColorPicker as an entry point. You can easily initialize the panel using

ColorPicker colorPicker = new ColorPicker(true, true);
colorPicker.addColorListener(colorModel -> System.out.println(colorModel.getColor()));

This creates a color picker component with expert controls and opacity settings. If the user selects a color, the color listener will be notified.

🌐 Localization

The color picker supports localization. You can set the locale by passing it to the constructor:

ColorPicker colorPicker = new ColorPicker(true, true, Locale.FRENCH);
// or
ColorPickerDialog.showDialog(null, Color.GREEN, Locale.FRENCH);

Currently, the following languages are supported:

  • English
  • Español
  • Français
  • Deutsch
  • Português
  • Русский

🔨 Building

Please use Maven to build and test the project.

mvn install

This will install the version to your local repository. You can now include it:

<dependency>
    <groupId>org.drjekyll</groupId>
    <artifactId>colorpicker</artifactId>
    <version>1.4.4-SNAPSHOT</version>
 </dependency>

or Gradle with Groovy DSL:

implementation 'org.drjekyll:fontchooser:1.4.4-SNAPSHOT'

or Gradle with Kotlin DSL:

implementation("org.drjekyll:fontchooser:1.4.4-SNAPSHOT")

🤝 Contributing, Credits and History

Please see here: Contributing

This color picker was a part of the javagraphics project (http://javagraphics.blogspot.com), initiated by Jeremy Wood. The javagraphics project is a collection of small stand-alone projects.

The original color picker component is copyright 2011 by Jeremy Wood.

📜 License

This modification of the color picker is released under a BSD 3-Clause license. More details can be found here:

https://opensource.org/licenses/BSD-3-Clause

📢 Release Notes

2.0.1

1.4.8

1.4.5

Prevent NPE on resize (#26)

1.4.3 and 1.4.4

Fixed null-pointer exception on changing slider

1.4.2

  • Introduced Lombok
  • Migrated to JUnit 5
  • Updated dependencies and plugins
  • Migrated to GitHub

colorpicker's People

Contributors

dependabot[bot] avatar dheid avatar nilon123456789 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

colorpicker's Issues

[BUG] Color slider doesn't update when using setColor()

Describe the bug
setColor() doesn't seem to update the position of the color slider (neither hue, brightness or saturation is updated)

Code snippets

public void setAccentColor(Color accentColor) {
    accentColorPicker.setColor(accentColor);
}

Capture

[BUG] NPE on using slider

Describe the bug
An NullPointerException is thrown on using the slider (tried in UiBooster test class)

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "javax.swing.JSlider.getOrientation()" because "this.slider" is null
	at com.bric.colorpicker.colorslider.SliderMouseListener.updateSliderValue(SliderMouseListener.java:24)
	at com.bric.colorpicker.colorslider.SliderMouseListener.mouseDragged(SliderMouseListener.java:42)
	at java.desktop/java.awt.Component.processMouseMotionEvent(Component.java:6662)
	at java.desktop/javax.swing.JComponent.processMouseMotionEvent(JComponent.java:3360)
	at java.desktop/java.awt.Component.processEvent(Component.java:6383)
	at java.desktop/java.awt.Container.processEvent(Container.java:2263)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4990)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4822)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4919)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4565)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4489)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2769)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4822)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:117)
	at java.desktop/java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:190)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:316)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

Code snippets
Used this code

Expected behavior
Changing the saturation of the color and not throw an exception 😊

[BUG] Illegal argument exception when color wheel is tiny

Describe the bug
When the component gets too small such as when the frame is resized, the color wheel disappears entirely. However, the selection handle/circle is still visible and creates an exception when you click on it.

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: The saturation value (-5.3851647) must be between [0,1]
	at com.bric.colorpicker.ColorPickerPanel.setHSB(ColorPickerPanel.java:460)
	at com.bric.colorpicker.ColorPickerPanel$ColorPickerMouseInputListener.mousePressed(ColorPickerPanel.java:682)

[REQUEST] Horizontal layout for controls

By default the controls and preview swatch are displayed to the right of the color wheel. I'd like to see more customization available by default, specifically an option to have all the modes displayed below the color wheel by default laid out horizontally rather than vertically. It would save a lot of time :)

[BUG] Localization not implemented for ColorPicker/Option

Describe the bug
The ColorPicker class is not using localization.

Code snippets

ResourceBundle.getBundle("com.bric.colorpicker.resources.ColorPicker"); // This is not calling the getBundle with a local.

Expected behavior

ResourceBundle.getBundle("com.bric.colorpicker.resources.ColorPicker", local); // local being the current active localization

[BUG] NullPointerException

I have a colour picker inside a dockable frame from DockingFrames. It starts off minimized and when it is shown the colour picker throws an NPE

java.lang.NullPointerException
	at java.desktop/javax.swing.plaf.basic.BasicSliderUI.calculateFocusRect(BasicSliderUI.java:674)
	at java.desktop/javax.swing.plaf.basic.BasicSliderUI.calculateGeometry(BasicSliderUI.java:660)
	at com.bric.colorpicker.colorslider.ColorSliderUI.access$000(ColorSliderUI.java:47)
	at com.bric.colorpicker.colorslider.ColorSliderUI$ResizeListener.componentResized(ColorSliderUI.java:207)
	at java.desktop/java.awt.AWTEventMulticaster.componentResized(AWTEventMulticaster.java:168)
	at ...

[BUG] Install error: JVMTest.checksWhetherSystemIsMac:23

Describe the bug
In bash terminal, MacOS 14.3.1, 17.0.10+13-LTS
I type mvn install and get

[INFO] Running com.bric.colorpicker.JVMTest
[ERROR] Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.031 s <<< FAILURE! -- in com.bric.colorpicker.JVMTest
[ERROR] com.bric.colorpicker.JVMTest.checksWhetherSystemIsMac -- Time elapsed: 0.020 s <<< FAILURE!
org.opentest4j.AssertionFailedError:

Expecting value to be false but was true
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at com.bric.colorpicker.JVMTest.checksWhetherSystemIsMac(JVMTest.java:23)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] JVMTest.checksWhetherSystemIsMac:23
Expecting value to be false but was true
[INFO]
[ERROR] Tests run: 8, Failures: 1, Errors: 0, Skipped: 0

Expected behavior
The build completes with no test failures

Additional context
I also got a failure when using Java 1.8.0_292-b10

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.