Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #8792

Attempting to set the color of a JTextField

From "John L." <johnlarew@sbcglobal.net>
Newsgroups comp.lang.java.programmer
Subject Attempting to set the color of a JTextField
Date 2011-10-14 07:15 -0700
Organization http://groups.google.com
Message-ID <c72ebf3b-6aad-457c-be87-5d7a992e0d9e@h5g2000vbf.googlegroups.com> (permalink)

Show all headers | View raw


I'm trying to change the color of a JTextField. There are many
interesting discussions on much more detailed topics in other posts.

Here is my best attempt, which does NOT work as I might reasonably
expect:

class ITextField extends JTextField
{
   private String s1 = null;
   public void setText(String s) {
      s1 = s;
   }
   public void paintComponent(Graphics g) {
      super.paintComponent(g);
      Graphics2D g2 = (Graphics2D) g;
      if (s1 != null) {
         g2.setPaint(Color.RED);
         g2.drawString(s1,0,0);
      }
   }
}

Thanks in advance for any help or insight you may be able to provide.

Back to comp.lang.java.programmer | Previous | NextNext in thread | Find similar


Thread

Attempting to set the color of a JTextField "John L." <johnlarew@sbcglobal.net> - 2011-10-14 07:15 -0700
  Re: Attempting to set the color of a JTextField Knute Johnson <nospam@knutejohnson.com> - 2011-10-14 07:21 -0700
    Re: Attempting to set the color of a JTextField "John L." <johnlarew@sbcglobal.net> - 2011-10-14 08:05 -0700
      Re: Attempting to set the color of a JTextField Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-10-14 10:42 -0700
        Re: Attempting to set the color of a JTextField "John L." <johnlarew@sbcglobal.net> - 2011-10-19 07:16 -0700
  Re: Attempting to set the color of a JTextField Roedy Green <see_website@mindprod.com.invalid> - 2011-10-14 09:44 -0700

csiph-web