Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8091921

System Colors (With implementation technique)

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • None
    • javafx
    • All

      One of the most basic needs of any user interface is access to user preferences for system colors. Using Java AWT directly is bulky since implementations are not guaranteed to provide AWT support. Below is a solution I am using which is working well.


      1. Create an abstract class which requires non-static methods for accessing all system colors (*.SystemColorsTemplate)

      2. Create a class which provides default colors (*.DefaultSystemColors) by extending class #1

      3. Create a class which provides AWT system colors by extending class #1 (*.AWTSystemColors)

      4. Create a class named *.SystemColors which provides static methods for accessing system colors, a static variable of type #1 which holds the currently applied system colors. The class should contain a static method for accessing and initializing this value. For my implementation if the value is null I using Class.forName to check for awt support and assign the AWTSystemColors inside a try and then inside the cache() I assign DefaultSystemColors.

      This method is working for me very well within a production environment and performs as a cache for the existence of AWT support which makes it fast. In my SystemColors class I don't allow users to define custom colors as this could create problems in a GUI if the system colors keep changing. I think it would be good to implement this feature in your stable release.

      Best Regards,
       Ralph Ritoch

            Unassigned Unassigned
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported: