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


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

Re: Attempting to set the color of a JTextField

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.21.MISMATCH!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe12.iad.POSTED!83aa503d!not-for-mail
From Daniel Pitts <newsgroup.nospam@virtualinfinity.net>
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1
MIME-Version 1.0
Newsgroups comp.lang.java.programmer
Subject Re: Attempting to set the color of a JTextField
References <c72ebf3b-6aad-457c-be87-5d7a992e0d9e@h5g2000vbf.googlegroups.com> <j79ghg$4lm$1@dont-email.me> <b33e0b12-fcef-46c5-88c7-8f1dcd45a19f@h14g2000yqi.googlegroups.com>
In-Reply-To <b33e0b12-fcef-46c5-88c7-8f1dcd45a19f@h14g2000yqi.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Lines 35
Message-ID <Yv_lq.763$AF3.464@newsfe12.iad> (permalink)
X-Complaints-To abuse@newsrazor.net
NNTP-Posting-Date Fri, 14 Oct 2011 17:42:16 UTC
Date Fri, 14 Oct 2011 10:42:15 -0700
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8801

Show key headers only | View raw


On 10/14/11 8:05 AM, John L. wrote:
> I might report that this new reasonable attempt failed also:
>
> 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) {
>           setOpaque(true);
>           setForeground(Color.RED);
>           g2.drawString(s1,0,0);
>           repaint();
>        }
>     }
> }
>
> BTW, the background is not red.
>
> Thanks in advance for any help or insight you may provide.

Don't set those in the paintComponent method, they are meant to be set 
by the code constructing the field.  Extending JTextField is the wrong 
approach.


JTextField textField = new JTextField();
textField.setForeground(Color.RED);


That should do what you want.

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next 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