Color constants demo

This demo displays a palette containing the JavaFX color constants. It can be modified to display any list of colors. For more information on JavaFX colors see: Color.


Demo



Source Code

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.input.MouseEvent;
 
/**
 * @author code-better.com
 */
 
def colors = [
    "ALICEBLUE", "ANTIQUEWHITE", "AQUA", "AQUAMARINE", "AZURE", "BEIGE",
    "BISQUE", "BLACK", "BLANCHEDALMOND", "BLUE", "BLUEVIOLET", "BROWN",
    "BURLYWOOD", "CADETBLUE", "CHARTREUSE", "CHOCOLATE", "CORAL",
    "CORNFLOWERBLUE", "CORNSILK", "CRIMSON", "CYAN", "DARKBLUE", "DARKCYAN",
    "DARKGOLDENROD", "DARKGREEN", "DARKGREY", "DARKKHAKI",
    "DARKMAGENTA","DARKOLIVEGREEN", "DARKORANGE", "DARKORCHID", "DARKRED",
    "DARKSALMON", "DARKSEAGREEN", "DARKSLATEBLUE",
    "DARKSLATEGREY", "DARKTURQUOISE", "DARKVIOLET", "DEEPPINK", "DEEPSKYBLUE",
    "DIMGREY", "DODGERBLUE", "FIREBRICK", "FLORALWHITE",
    "FORESTGREEN", "FUCHSIA", "GAINSBORO", "GHOSTWHITE", "GOLD", "GOLDENROD",
    "GREEN", "GREENYELLOW", "GREY", "HONEYDEW", "HOTPINK", "INDIANRED",
    "INDIGO", "IVORY", "KHAKI", "LAVENDER", "LAVENDERBLUSH", "LAWNGREEN",
    "LEMONCHIFFON", "LIGHTBLUE", "LIGHTCORAL", "LIGHTCYAN",
    "LIGHTGOLDENRODYELLOW", "LIGHTGREEN", "LIGHTGREY", "LIGHTPINK",
    "LIGHTSALMON", "LIGHTSEAGREEN", "LIGHTSKYBLUE",
    "LIGHTSLATEGREY", "LIGHTSTEELBLUE", "LIGHTYELLOW", "LIME", "LIMEGREEN",
    "LINEN", "MAGENTA", "MAROON", "MEDIUMAQUAMARINE", "MEDIUMBLUE",
    "MEDIUMORCHID", "MEDIUMPURPLE", "MEDIUMSEAGREEN", "MEDIUMSLATEBLUE",
    "MEDIUMSPRINGGREEN", "MEDIUMTURQUOISE", "MEDIUMVIOLETRED", "MIDNIGHTBLUE",
    "MINTCREAM", "MISTYROSE", "MOCCASIN", "NAVAJOWHITE", "NAVY", "OLDLACE",
    "OLIVE", "OLIVEDRAB", "ORANGE", "ORANGERED", "ORCHID", "PALEGOLDENROD",
    "PALEGREEN", "PALETURQUOISE", "PALEVIOLETRED", "PAPAYAWHIP", "PEACHPUFF",
    "PERU", "PINK", "PLUM", "POWDERBLUE", "PURPLE", "RED", "ROSYBROWN",
    "ROYALBLUE", "SADDLEBROWN", "SALMON", "SANDYBROWN", "SEAGREEN", "SEASHELL",
    "SIENNA", "SILVER", "SKYBLUE", "SLATEBLUE", "SLATEGREY",
    "SNOW", "SPRINGGREEN", "STEELBLUE", "TAN", "TEAL", "THISTLE", "TOMATO",
    "TURQUOISE", "VIOLET", "WHEAT", "WHITE", "WHITESMOKE", "YELLOW",
    "YELLOWGREEN" ];
    // removed duplicate spellings of grey/gray
 
var backColor = "WHITE";
 
 
Stage {
    title: "Color Constants"
    scene: Scene {
        width: 600
        height: 700
        content: [
            Rectangle {
                width:600  height:700
                fill: bind Color.web(backColor)
            }
 
            Text {
                x: 40  y: 650
                content: bind backColor
                fill: bind if (backColor=="BLACK") then Color.WHITE else Color.BLACK
            }
            for(color in colors){
                Rectangle{
                    fill: Color.web(color)
                    x: (indexof color mod 12) * 50
                    y: (indexof color / 12) * 50
                    width: 50
                    height: 50
                    onMousePressed: function(me:MouseEvent){ 
                        backColor=color;
                    }
                }
            }
        ]
    }
}

On Tue, 05/26/2009 - 07:13 Anonymous (not verified) said:

I'm getting a crazy stack trace. JVM is trying to load a class named from an XML header. Can you fix it?

Thanks,

Dave

Exception in thread "AppletLauncher-Startup" java.lang.NoClassDefFoundError: IllegalName: (Unknown Source)
at org.jdesktop.applet.util.JNLPAppletLauncher.parseJNLPExtensions(Unknown Source)
at org.jdesktop.applet.util.JNLPAppletLauncher.initResources(Unknown Source)
at org.jdesktop.applet.util.JNLPAppletLauncher.initAndStartApplet(Unknown Source)
at org.jdesktop.applet.util.JNLPAppletLauncher.access$000(Unknown Source)
at org.jdesktop.applet.util.JNLPAppletLauncher$1.run(Unknown Source)
JNLPAppletLauncher: static initialize

On Fri, 05/29/2009 - 15:22 codebetter said:

I can't seem to reproduce the problem. Was it occurring when running the demo from the compiled code or just from the website? If from the website, do the other examples have issues running too?