Results 1 to 3 of 3
  1. #1
    Y. Progammer is offline Member
    Join Date
    Feb 2010
    Posts
    68
    Rep Power
    0

    Default unable to change the TextArea.background !

    Java Code:
    import javax.swing.*;
    import javax.swing.JPanel;
    import javax.swing.UIManager;
    import javax.swing.plaf.ColorUIResource;
    import java.awt.Color;
    
    public class EasyToolTip extends JPanel {
    
        JTextArea t = new JTextArea(10, 10);
    
        EasyToolTip() {
            UIManager.put("ToolTip.background", new ColorUIResource(Color.CYAN));
            UIManager.put("TextArea.background", new ColorUIResource(25, 25, 25));
            setToolTipText("This is also a way to change the color of the tooltip in your application!");
            add(t);
        }
    
        public static void main(String[] args) {
            javax.swing.JFrame frame = new javax.swing.JFrame("EasyToolTip");
            frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
            frame.add(new EasyToolTip());
            frame.setSize(1280, 770);
            frame.setVisible(true);
        }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    The order in which code gets called is what matters here since you are creating your JTextArea before the UIManager has had a chance to change the default background. Change that and your program will change its display:
    Java Code:
    import javax.swing.*;
    import javax.swing.JPanel;
    import javax.swing.UIManager;
    import javax.swing.plaf.ColorUIResource;
    import java.awt.Color;
    
    public class EasyToolTip extends JPanel {
    
      JTextArea t; // = new JTextArea(10, 10);
    
      EasyToolTip() {
        UIManager.put("ToolTip.background", new ColorUIResource(Color.CYAN));
        UIManager.put("TextArea.background", new ColorUIResource(25, 25, 25));
        t = new JTextArea(10, 10);
        setToolTipText("This is also a way to change the color of the tooltip in your application!");
        add(t);
      }
    
      public static void main(String[] args) {
        javax.swing.JFrame frame = new javax.swing.JFrame("EasyToolTip");
        frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
        frame.add(new EasyToolTip());
        frame.setSize(1280, 770);
        frame.setVisible(true);
      }
    }

  3. #3
    Y. Progammer is offline Member
    Join Date
    Feb 2010
    Posts
    68
    Rep Power
    0

Similar Threads

  1. how to change windows xp background image through java
    By erosenthil in forum Advanced Java
    Replies: 1
    Last Post: 08-18-2009, 12:57 PM
  2. Replies: 4
    Last Post: 03-21-2009, 05:48 PM
  3. my code doesn't change background color
    By javanoobita in forum New To Java
    Replies: 5
    Last Post: 02-22-2009, 04:30 AM
  4. JButton onClick change color background
    By behrk2 in forum AWT / Swing
    Replies: 6
    Last Post: 07-09-2008, 04:54 PM
  5. when muse pressed the background change
    By pcman in forum Java Applets
    Replies: 1
    Last Post: 03-17-2008, 11:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •