🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #9299

Re: read-only JTextField not greyed-out ?

#9299
From: David M. Karr
Date: Tue, 25 Apr 2000 00:00
25 lines
1595 bytes
>>>>> "Stephen" == Stephen Legge <stephen@cryptocard.com> writes:

    Stephen> When I set a JTextField's editable attribute to false, it stays
    Stephen> white -- I'd like it to be greyed out like the Windows standard
    Stephen> for a read-only edit-box.  Is there an easy way to do this or do I
    Stephen> have to change the color myself?

    Stephen> The problem is, I don't want to change colors if I don't have to
    Stephen> because it looks fine in other "Look&Feel"s, like Java L&F for
    Stephen> instance.

I did this before using a custom L&F, but if you already use a JTextField
subclass (I do), then it would be easy to add the following method to your
JTextField subclass.  I got this idea from "Kleopatra
<fastegal@zedat.fu-berlin.de>", but I have not tried it yet.

    public void setEnabled(boolean enabled)
    {
       if (enabled == isEnabled()) return;
       super.setEnabled(enabled);
       if (enabled)
          setBackground(UIManager.getColor("TextField.background"));
       else
          setBackground(UIManager.getColor("ComboBox.disabledBackground"));
    }
Technical Details
Message-ID: <uog6yuqfm.fsf@attws.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <8e46ul$4nf4@bornews.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,51d919679d20f6ec
X-Google-Attributes: gid111d45,public
From: david.karr@attws.com (David M. Karr)
Subject: Re: read-only JTextField not greyed-out ?
Date: 2000/04/25
Message-ID: <uog6yuqfm.fsf@attws.com>
X-Deja-AN: 615512582
Sender: DKarr@WA02513
References: <8e46ul$4nf4@bornews.borland.com>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.swing