Change colors to all components in a consistent way

Is there a way to change color to all components of an application (or of a JFrame), such as all JButtons backgrounds, JFrame backgrounds etc.?
I suppose i've to deal with UIManager defaults, but is there some facility, or some check-list to help achieve this task?.
Thanks in advance
Agostino

Check out my ComponentMapper class. You could do it with this by running the mapper on the contentpane (and potentially the JMenuBar too if you like)
You are welcome to use and modify this code but please don't change the package or take credit for it as your own work
tjacobs.util.ComponentMapper
======================
package tjacobs.util;
import java.awt.Component;
import java.awt.Container;
import java.awt.TextComponent;
import javax.swing.JFileChooser;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.JTextComponent;
public class ComponentMapper {
     public static interface MappedFunc {
          public void func(Component c);
     public static void map(Component c, MappedFunc func) {
          func.func(c);
          if (c instanceof Container) {
               Container con = (Container)c;
               int count = con.getComponentCount();
               for (int i = 0; i < count; i++) {
                    map(con.getComponent(i), func);
     public static void main(String[] args) {
          JFileChooser fc = new JFileChooser();
          MappedFunc mf = new MappedFunc() {
               public void func(Component c) {
                    if (c instanceof JTextComponent) {
                         System.out.println("found");
                         final JTextField tf = ((JTextField)c);
                         tf.setEditable(false);
                         tf.getDocument().addDocumentListener(new DocumentListener() {
                              public void insertUpdate(DocumentEvent de) {
                                   Runnable r = new Runnable() {
                                        public void run() {
                                             tf.setText("");
                                   SwingUtilities.invokeLater(r);
                              public void removeUpdate(DocumentEvent de) {
                              public void changedUpdate(DocumentEvent de) {
                         while (c != null) {
                              System.out.println(c.getClass());
                              c = c.getParent();
                         //disable the textfield
          map(fc, mf);
          fc.showSaveDialog(null);
}

Similar Messages

  • Can I change color of all objects at ones ?

    Hello guys
    I understand that's very fundamental question, and I promise I search the forum prior to posting, but perhaps it's my bad english and wrong phrasing, that leads to poor results. So if that has been discuss, please kindly don't waste your time, just link me to the post and I will read away.
    I have very complex file, with hundreds of paths, shapes, text, outlined text,  etc... It's a brochure with graphs, scematich drawings and text.
    Last moment, the client like the reverse the colors from (current) Black on white, to all White on dark gray background.
    Problem is, I can't seem to find easy way to just change the colors, without selecting one by one, every single object. When I selest all and choose white, it start filling paths with solid fill... Editing it wastes allot of my time and I have many pages to do.
    Is there any way to simple change color of everything at once, just from black to white ? Or do I have to go object by object manually ?
    Thank you very much, for all the help so far, and I'm sincerly sorry to waste your time if that has been covered previously.
    Good day
    ciao ciao
    Monika

    Thank you both for such prompt follow up. I know it's just typing and it's easy but I sincerly mean it. Thank you.
    The INVERT work on some images.
    The "SAME" seem to work funny way. When I select STROKE COLOR, it does nothing, but when I select WIGHT then it does and in fact I'm able to change lots of strokes at once with ease. Even tho I'm left with few small bits here and there which I need to change manually, it is certainly far better than doing one by one.
    Thanks a lot for the help, it's what I was looking for.
    By the way   I not once used the SAME menu. Feel so lame, given I use AI (not daily but often) for few years now... Shame.
    Thank you and you guys have a great day
    xoxo

  • Change colors of all controls

    Can I programmaticaly to change (to switch between two options) the color of ALL controls by some common command without dealing with property node of each control?
    Thank you,
    Boris

    Pnt,
    Thank you. I tried it as in example with decorations: http://zone.ni.com/devzone/cda/epd/p/id/5217.
    But it looks that this option is not available for controls.
    Attachments:
    decorations.png ‏2 KB
    controls.png ‏7 KB

  • Changing font and background color for all components

    Hi,
    This is my first time writing a GUI, and I'm pretty new to Swing and Java. I just recently switched from C++, and so far Java seems to be doing a nice job =)
    Currently I have a gazilion components (textfields, labels, panels) and I'm wondering if there is a way to change their background/foreground colours without adding in setBackground/setForeground for every single component.
    I've done some researching onto using Look and Feel, but there aren't any current ones that suits my needs. And everyone seems to mention that programming your own is pretty complicated.
    My boss wants a slick white text on black background interface, so you can imagine that he's not very impressed with the current default greyish colours =)
    Thank you for any help!
    Cindy

    Hi Cindy,
    I'm not sure how effective a solution this will be, but you could try:UIManager.put("TextField.background", Color.BLACK); // Default text field background becomes blackThere are many more defaults you'd have to change and could probably achieve it more reliably and simply by creating or editing the properties file that controls the way the look and feel (even if it's the default) is implemented. Take a look at:
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/UIManager.htmlHope this is helpful
    Chris.

  • Howto change color for all elements

    I want to update the formatting for some existing Keynote presentations. Applying a new Theme does most of the work, but there are some things that are not updated to the new theme. For example: background color of certain text boxes -- and the color of actual bullets for bullet points.
    In the case of these presentations:
    - the background color of the textboxes is blue and I want them all to be transparent
    - the color of the bullets is blue and I want them all to be the default color/picture of the particular theme
    I realize this is because Keynote is "respecting" textbox formatting changes I have made in the original, but it would be nice if I could over-ride this "respect" somehow. It is easy to select all the text of a Keynote presentation and apply various ways to all the text. Is there a trick for selecting all textboxes (and changing the background color of them) -- or of specifying something to the effect of, "apply the following format to all the bullets in a presentation?

    Ok, in that file, you'll find a set of parameters that looks like this.
    sfa:r="1" sfa:g="0" sfa:b="0" sfa:a=".5"
    Those stand for the red, green, and blue of a color and the last one is the opacity. This particular combination would create a red object with 50 percent opacity. Still looking for which one of these controls the background of a text box.
    You know, it looks like if you go through the file searching for sf:fill and deleting that section, then that removes the fill. Once you find the right section, one find and replace would do it for you. It's one of those things that makes me wish I was handy enough with Automator and/or Applescript.
    Message was edited by: Kyn Drake

  • Changing colors on all slides

    I have a presentation with 84 slides. My text is white. I want to change all slides to black text with a white background. What's the quickest way to do this short of manually changing each slide separately?

    You should be able to change the slide master(s) to get the appearance you want. In the View menu, select "Show Master Slides". When you click on one of the masters, you can edit it, and any slide that has that as its master will be changed. So, you can change a master's background to white, and change the text on it to black, and all slides using that master will have white backgrounds with black text.
    Note that the text on slides will only be changed if that text was typed into the default text box of the slide (in other words, if it used the master's text box). If the text was added as a separate object, you'll have to change that text by hand.
    PowerMac G5   Mac OS X (10.4.4)  

  • How to change color of canvas?

    I made sure the background color swatch in the lower left of the tool box was set to blue.  Then I went to Image>Resize>Canvas Size> and changed the sizes.  Then I set the Color Extension to the background color blue, and the little box to the right of this showed the blue I wanted.
    Then I clicked OK.
    The sizes changed properly, but the color won't change colors at all.  It stays an ugly putty brown, no matter that I have tried every single way in that color extension box pull-down menu.
    Any help will be much appreciated.

    Try this:
    Set the background color (lower left) to blue
    Go to File>new>blank file. Enter width & height in inches for the desired document, resolution 240-300px/in for printing, background contents: background color.
    OK

  • How to change background color of all JTextFields

    Hi,
    I have made the code below to show all properties available in UIDefaults.
    Then, I would like to have the same behaviour that this Web Forum, that sets a yellow color in background of "Subject input text", when the user focus this field. I want this in my Swing apps, when user changes from a field to other. But I didn't find something like "TextField.focusBackground" to do this...
        UIDefaults uidef = UIManager.getDefaults();
        Enumeration enumkey = uidef.keys();
        Enumeration enumdef = uidef.elements();
        while (enumdef.hasMoreElements()) {
          System.out.println(
            enumkey.nextElement().toString() + " = " +
            enumdef.nextElement().toString());
        }I would like to set up colors in the beggining of my Swing app, something like this for all components:
    UIManager.put("TextField.focusBackground", java.awt.Color.YELLOW);
    UIManager.put("PasswordField.focusBackground", java.awt.Color.YELLOW);
    UIManager.put("TextArea.focusBackground", java.awt.Color.YELLOW);
    ...

    You can use the KeyBoardFocusManager. Start with the code below and customize to your requirements:
    KeyboardFocusManager.getCurrentKeyboardFocusManager()
         .addPropertyChangeListener("permanentFocusOwner", new PropertyChangeListener()
         public void propertyChange(PropertyChangeEvent e)
              if (e.getNewValue() instanceof JTextField)
                   JTextField textField = (JTextField)e.getNewValue();
                   textField.selectAll();
    });

  • Change BgColors, FgColors for all Components in a Container?

    Is there a possibility to change the Background Color, the Foreground Color and the Fontsettings for all Components in a Container? Each Component in the Container should get the Colorsettings of the Container...

    Just overwrite the add, setBackground(), setForeGround() and the Font-methods of the Container:
    public void add(Component c){
    super.add(comp);
    comp.setBackground(...);
    comp.setForeground(...);
    //...the Font-stuff
    public void setBackground(Color c){
    for(int i=0;i< getComponentCount(), ++i){
    getComponenetAt(i).setBackground(c);
    //the same for setForeground and the Font-methods.

  • My background color for all pages has changed to pink, how do I get it back to white?

    The background color in all of my screens has switched to pink. How do I get it back to white? I wonder if it changed when I was shopping in a web site and had clicked on a pink watch(?)

    Check the default color settings:
    *Tools > Options > Content : Fonts & Colors > Colors
    * [X] "Allow pages to choose their own colors, instead of my selections above"
    *https://support.mozilla.com/kb/Changing+fonts+and+colors

  • How do I change the color of all the text in a PDF?

    Hi.
    I have a large PDF, over 1000 pages. Some of the text is highlighted which makes it difficult to see on my preferred document background. In Acrobat XI how do I change the color of all the text in the document back to black please? Although solutions using any other software will be much appreciated too.
    I searched this forum already, and the same question was asked back in 2007 when it appears the only solution was to use an expensive third party plugin.
    Thanks.

    I know of no new solutions since 2007 except the ones you found.
    You could use the Accessibility Preferences > Change Document Colors to choose a text color. However, this is an individual preference and cannot be set as a default for others opening the document.

  • Changing the hightlight color for all existing highlighted text

    Is there a quick way to change the hightlight color of all existing highlighted text in a document? Thanks.

    Never mind I found it. Open the Comment panel, select all existing comments, right-click and select Properties, change to your desired setting, click OK.

  • ALL SHAPES LAYERS SUDDENLY CHANGED COLOR WITH SOME ACCIDENTALLY USED KEYBOARD SHORT CUT PLEASE HELP

    I was working away in photoshop on an INCREDIBLY important file and suddenly all of my shape layers inverted... there is NOTHING in the history and I have literally tried everything I can think of. this is seriously a crucial issue and i really need this to be fixed. if ANYONE knows anything please help. I'm posting a screenshot of what it looked like and what it looks like now. naturally adobe wont let me call them or do ANYTHING to get immediate help with this absolutely infuriating problem so if someone out there could help that would be great. SERIOUSLY regretting using photoshop, it is so infuriating even after 7 years of using it.
    ^^ this is what the colors looked like
    and VV this is what they look like now. as far as i can tell, its only the shape layers that have changed color. I have tried everything and nothing works.
    roughly, all the yellow turned green and all the red and white turned black? I have no idea. please PLEASE someone help me.

    The colors are present even when  I exported Jpegs from the photoshop file. Gamut warning is off. the difficult thing with screenshots is that the image appears in different colors at different sizes... which is bizzare.. at the full shape, some of the shape layers appear fine as pictured below
    and then when i zoom in this happens

  • All components not updating when I change the L&F

    I have developed a GUI and want Windows LookAndFeel for it. Please excuse me if I use some terms incorrectly. I'll explain my class structure first -
    1. class MainWindow - Contains the main method and invokes MainFrame
    2. class MainFrame - Creates the basic GUI and all the components and their event-handlers
    3.class MainPanel - Contains the actions to be taken in response to an event in MainFrame
    4. Dialog Boxes : Their are several classes implementing several dialog boxes which I load as needed.
    I have changed the L&F in the MainFrame class after all the MainFrame class components have been loaded. I have also used updateComponentTreeUI( ) to update all components already formed. I found out that not all components are having the Windows L&F when I tried out a JProgressBar. Instead of the green-broken progress indicator (Windows XP style), it was showing the gray-filled indicator (Java style). Then I noticed even the Menu Items are having the default L&F. Can anyone comment. Not giving any code because I am not sure which part of the huge GUI code should I post, i.e. where the problem really lies.

    You just said it doesn't work for a menu. So you
    create a frame with a menu and a menu item. About 10
    lines of code. Then you add two buttons one to switch
    to the Windows LAF the other to the Metal LAF.
    Another 10 lines of code. Now you have your demo
    program.No no, you din't get me. I know the basics regarding L&F. All the components are working fine, but that JProgressBar is not showing the XP view. Forget the JMenuItems, I am not sure the view is Windows L&F or Metal L&F, but I am sure the JProgressBar is not Windows L&F (while the rest of the components in the dialog box are perfect). Could this be due to something that I missed out while implementing the JProgressBar. But the Windows L&F is loaded before the dialog box containing the progress bar comes in. Your answer to my last Swing post helped me a lot. Hope you (or anyone else) can help me with this too

  • HT4993 I changed my "invert colors" to negative and i love the way the apps look. Is there anyway that i can keep the apps looking like that but keep all my pictures the normal colors??

    I changed my "invert colors" to negative and i love the way the apps look. But is the anyway i can keep all the apps looking like that but keep all my pictures the normal colors?

    no

Maybe you are looking for