Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (739)
Games in Android Showcase (224)
games submitted by our members
Games in WIP (820)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  architecture: best way to implement a color palette  (Read 1579 times)
0 Members and 1 Guest are viewing this topic.
Offline skytomorrownow

Junior Devvie





« Posted 2006-08-19 19:24:42 »

i'm building the gui for my app mostly using swing components. i know that at somepoint i am going to want to tweak the coloring of the interface. so instead of hardcoding the colors into each component, i've created a simple object to wrap public fields of type Color. however, this means that i have to create this aforementioned ColorPalette object to access it from within my gui components.

in action, it might look like this:

1  
2  
3  
ColorPalette cp = new ColorPalette();
... (somewhere later in the component's code) ...
this.setBackground( cp.bkgd );


obviously this will save time later if i want to tweak colors, or even give the user control over some things. however, it seems kind of clunky. i had a suspicion that some java guru might have a slicker way to approach global setttings.

if i make the ColorPalette a final class, will that mean i don't have to instantiate it each time?

any ideas approaches to this kind of a typical problem would be great.

thx.
Offline Ask_Hjorth_Larsen

Junior Devvie




Java games rock!


« Reply #1 - Posted 2006-08-20 01:34:32 »

It is possible to design your own look-and-feel. I have not done this, but I believe it would be the proper way to solve the problem in general.  There's some interesting stuff at http://java.sun.com/products/jfc/tsc/articles/lookandfeel_reference/index.html#system_colors which allows you to globally control the appearance of components. Or perhaps you can do something with the Substance look-and-feel which someone mentioned in another thread (Commander Keith?).
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #2 - Posted 2006-08-20 03:42:11 »

Look and feels usually use some kind of theme which can be overridden. Take a look at... lets see...

<jdk>/demo/jfc/Metalworks/src/PropertiesMetalTheme.java

There you can see a property based theme, which supports the 3 primary/secondary colors and "black"/"white".

You can also use UIManager.put for overriding specific things. Here is some list with the default values:
http://kaioa.com/k/JavaUIDefaults.txt

You use it like:
UIManager.put("ScrollBar.background", new ColorUIResource(255,255,255));

or:
UIManager.put("ToolTip.border", BorderFactory.createEmptyBorder());

弾幕 ☆ @mahonnaiseblog
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline skytomorrownow

Junior Devvie





« Reply #3 - Posted 2006-08-20 04:53:09 »

hey great information. however, i'm definitely creating some custom UI elements such as a time ruler. however, it's mostly made from components. i have attached the image of the interface. it's purposely quite simple, and most of it is just various JComponents. you can see that they all share a simple color palette that i want to be able to change globally.

should i create a ColorPalette class to store my colors, then create it as a static field of a master abstract gui class? how would you design this?

any tips much appreciated.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 
Ecumene (56 views)
2017-09-30 02:57:34

theagentd (79 views)
2017-09-26 18:23:31

cybrmynd (187 views)
2017-08-02 12:28:51

cybrmynd (185 views)
2017-08-02 12:19:43

cybrmynd (192 views)
2017-08-02 12:18:09

Sralse (202 views)
2017-07-25 17:13:48

Archive (758 views)
2017-04-27 17:45:51

buddyBro (892 views)
2017-04-05 03:38:00

CopyableCougar4 (1441 views)
2017-03-24 15:39:42

theagentd (1324 views)
2017-03-24 15:32:08
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!