Article View: borland.public.jbuilder.java.swing
Article #623Re: Disable a button??
From: Davisote
Date: Sat, 26 Mar 2005 11:12
Date: Sat, 26 Mar 2005 11:12
65 lines
3624 bytes
3624 bytes
Thanks for the answer.
I've been trying to add this DocumentListener using the JBuilder interface
as it say in the page 19-30 of the manual of Borland (Learning Java with
JBuilder).
This is what we have to do:
Click the document property in the left column of the Inspector, then
right-click and choose Expose As Class Level Variable, but this option is
not enabled...., just one of them and when you select the option Regular the
document option it disappears.
Any suggestion
Thanks
"John McGrath [TeamB]" <ng-b@JPMcGrath.net> escribi๏ฟฝ en el mensaje
news:xn0e06k3u1mwvy000@newsgroups.borland.com...
> On 3/25/2005 at 1:36:55 PM, Davisote wrote:
>
>> This should be the same code to disable the button, but sometimes
>> For example, if I delete all the text the button doesn't disable
>>
>> void jTextField1_keyPressed(KeyEvent e) {
>> if (jTextField1.getText().length() > 0) {
>> jButton1.setEnabled(true);
>> }
>> else {
>> jButton1.setEnabled(false);
>> }
>> }
>
> The real problem here is that the code is listening to the wrong thing.
> The code needs to know when the text field is modified, but it listens for
> keyboard events. It is making the assumption that the contents of the
> text field will only be modified as the result of a keystroke, and that
> the text field will process the keystrokes before the listener. Neither
> of these assumptions are correct.
>
> The text field could be modified in response to keystrokes, but it could
> also change as the result of mouse events, bar code scans, voice commands,
> or whatever. In these cases, the code would not appropriately disable or
> enable the button if it listens for keystrokes.
>
> And although the order in which event listeners will be notified is not
> specified, the listener code will run *before* the text field processes
> the keystrokes. So the code will always be one step behind in disabling
> the button.
>
> The code needs to know when the text of the field changes. JTextField, as
> with all standard Swing components, does not actually store any data; that
> is stored in the model for the component. In the case of a JTextField and
> other JTextComponent subclasses, the model is a Document.
>
> So what the code needs to know is when the contents of the Document for
> the JTextField changes. That can be achieved by adding a DocumentListener
> to the Document.
>
> --
> Regards,
>
> John McGrath [TeamB]
>
> ---------------------------------------------------
> Before sending me e-mail, please read:
> http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID:
<424543b4@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<42441118@newsgroups.borland.com> <4244454a$1@newsgroups.borland.com> <42445a44@newsgroups.borland.com> <xn0e06k3u1mwvy000@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,cb273dd3cca84955 X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII From: "Davisote" <yeses@hotmail.com> Newsgroups: borland.public.jbuilder.java.swing References: <42441118@newsgroups.borland.com> <4244454a$1@newsgroups.borland.com> <42445a44@newsgroups.borland.com> <xn0e06k3u1mwvy000@newsgroups.borland.com> Subject: Re: Disable a button?? Date: Sat, 26 Mar 2005 11:12:52 -0000 Lines: 67 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 85.53.78.62 Message-ID: <424543b4@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1111835572 85.53.78.62 (26 Mar 2005 03:12:52 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail