Thread View: borland.public.jbuilder.java.swing
13 messages
13 total messages
Started by Davisote
Fri, 25 Mar 2005 13:24
Disable a button??
Author: Davisote
Date: Fri, 25 Mar 2005 13:24
Date: Fri, 25 Mar 2005 13:24
10 lines
1144 bytes
1144 bytes
Hi. I have a little problem. Just a JTextField and a JButton. if JTextField is null or is blank the JButton must be disabled and when it has something then enable the JButton. What I do is test the length of the JTextField but it doesn't work correctly. Anybody knows how is the correct method to do this?? Thanks
Re: Disable a button??
Author: Lori M Olson [TeamB]
Date: Fri, 25 Mar 2005 17:07
Date: Fri, 25 Mar 2005 17:07
36 lines
1956 bytes
1956 bytes
Davisote wrote:
> Hi.
> I have a little problem. Just a JTextField and a JButton. if JTextField is
> null or is blank the JButton must be disabled and when it has something then
> enable the JButton.
> What I do is test the length of the JTextField but it doesn't work
> correctly.
>
> Anybody knows how is the correct method to do this??
>
> Thanks
>
>
Why don't you post the code fragment that "doesn't work correctly" so we
can see why...
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
http://www.google.ca/advanced_group_search
Other Newsgroup Searches:
http://www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Re: Disable a button??
Author: Davisote
Date: Fri, 25 Mar 2005 18:36
Date: Fri, 25 Mar 2005 18:36
50 lines
2291 bytes
2291 bytes
Hi.
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);
}
}
Thanks
"Lori M Olson [TeamB]" <javadragon@techie.com> escribi� en el mensaje
news:4244454a$1@newsgroups.borland.com...
> Davisote wrote:
>
>> Hi.
>> I have a little problem. Just a JTextField and a JButton. if JTextField
>> is null or is blank the JButton must be disabled and when it has
>> something then enable the JButton.
>> What I do is test the length of the JTextField but it doesn't work
>> correctly.
>>
>> Anybody knows how is the correct method to do this??
>>
>> Thanks
>
> Why don't you post the code fragment that "doesn't work correctly" so we
> can see why...
>
> --
>
> Regards,
>
> Lori Olson [TeamB]
>
> ------------
>
> Save yourself, and everyone else, some time and search the
> newsgroups and the FAQ-O-Matic before posting your next
> question.
>
> Google Advanced Newsgroup Search
> http://www.google.ca/advanced_group_search
> Other Newsgroup Searches:
> http://www.borland.com/newsgroups/ngsearch.html
> Joi Ellis's FAQ-O-Matic:
> http://www.visi.com/~gyles19/fom-serve/cache/1.html
Re: Disable a button??
Author: Lori M Olson [TeamB]
Date: Fri, 25 Mar 2005 21:59
Date: Fri, 25 Mar 2005 21:59
36 lines
1916 bytes
1916 bytes
Davisote wrote:
> Hi.
> 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);
> }
> }
>
Try using a keyTyped event instead of a keyPressed.
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
http://www.google.ca/advanced_group_search
Other Newsgroup Searches:
http://www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Re: Disable a button??
Author: Davisote
Date: Sat, 26 Mar 2005 01:10
Date: Sat, 26 Mar 2005 01:10
43 lines
2041 bytes
2041 bytes
hi.
Sorry, but this event doesn't work at all.
Regards
"Lori M Olson [TeamB]" <javadragon@techie.com> escribi� en el mensaje
news:424489a2@newsgroups.borland.com...
> Davisote wrote:
>
>> Hi.
>> 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);
>> }
>> }
>>
>
> Try using a keyTyped event instead of a keyPressed.
>
> --
>
> Regards,
>
> Lori Olson [TeamB]
>
> ------------
>
> Save yourself, and everyone else, some time and search the
> newsgroups and the FAQ-O-Matic before posting your next
> question.
>
> Google Advanced Newsgroup Search
> http://www.google.ca/advanced_group_search
> Other Newsgroup Searches:
> http://www.borland.com/newsgroups/ngsearch.html
> Joi Ellis's FAQ-O-Matic:
> http://www.visi.com/~gyles19/fom-serve/cache/1.html
Re: Disable a button??
Author: John McGrath [TeamB]
Date: Sat, 26 Mar 2005 01:26
Date: Sat, 26 Mar 2005 01:26
48 lines
2949 bytes
2949 bytes
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
Re: Disable a button??
Author: 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
Re: Disable a button??
Author: John McGrath [TeamB]
Date: Sat, 26 Mar 2005 22:47
Date: Sat, 26 Mar 2005 22:47
19 lines
1747 bytes
1747 bytes
On 3/26/2005 at 6:12:52 AM, Davisote wrote:
> 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).
You do not say what JBuilder version you are talking about, so it is hard
to tell exactly what pages you are referring to. It would also be a good
idea to mention the chapter/section titles, since manuals are available in
different formats.
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Re: Disable a button??
Author: Davisote
Date: Sun, 27 Mar 2005 12:52
Date: Sun, 27 Mar 2005 12:52
31 lines
2233 bytes
2233 bytes
Right. I'm using JBuilder Enterprise 8.0.140.0 and the document is "Learning Java with JBuilder" Verison 4. In the Chapter 19, called "Building a Java Text Editor" in the Step 13: Hooking up event handling to the text area, there is the way I told you before about add the DocumentListener. Regards. "John McGrath [TeamB]" <ng-b@JPMcGrath.net> escribi� en el mensaje news:xn0e07ug01bdr2r002@newsgroups.borland.com... > On 3/26/2005 at 6:12:52 AM, Davisote wrote: > >> 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). > > You do not say what JBuilder version you are talking about, so it is hard > to tell exactly what pages you are referring to. It would also be a good > idea to mention the chapter/section titles, since manuals are available in > different formats. > > -- > Regards, > > John McGrath [TeamB] > > --------------------------------------------------- > Before sending me e-mail, please read: > http://www.JPMcGrath.net/newsgroups/e-mail.html
Re: Disable a button??
Author: John McGrath [TeamB]
Date: Sun, 27 Mar 2005 20:17
Date: Sun, 27 Mar 2005 20:17
48 lines
2989 bytes
2989 bytes
On 3/27/2005 at 7:52:37 AM, Davisote wrote:
> I'm using JBuilder Enterprise 8.0.140.0 and the document is "Learning
> Java with JBuilder" Verison 4.
> In the Chapter 19, called "Building a Java Text Editor" in the Step 13:
I do not have a copy of the JBuilder 8 documentation set, but the JBuilder
2005 docs have a tutorial by the same name, so that is what I am looking
at. You might want to check to see that it is the same as what you are
looking at. It is available at:
http://info.borland.com/techpubs/jbuilder/jbuilder2005/index1280x1024.html
Select the book, "Designing Applications with JBuilder", from the combo at
the top of the page, then Chapter 11, Step 13 from the table of contents
on the left.
On 3/26/2005 at 6:12:52 AM, Davisote wrote:
> > choose Expose As Class Level Variable, but this option is not enabled.
Are you saying that "Expose As Class Level Variable" appears in the menu,
but it is disabled? I tried this with JBuilder Enterprise 8.0.140.0 and
it worked for me. If that is what you are saying, would you please post
the code that you are viewing in the UI Designer?
> > just one of them
I do not understand this. Just one of what?
> > and when you select the option Regular the document option it
> > disappears.
The property exposure level controls what properties are visible. If you
set it to "Regular", only the most commonly used properties are shown.
"Expert" shows most properties, and "Hidden" shows all properties. Since
the document property is "Expert" level, it is not shown when you set the
property exposure level to "Regular". That is how it is supposed to work.
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Re: Disable a button??
Author: Davisote
Date: Sun, 27 Mar 2005 20:46
Date: Sun, 27 Mar 2005 20:46
67 lines
3625 bytes
3625 bytes
Hi again and thanks for asking. That link has the same documentation I use. After making many tests, I have discovered how to show "Expose As Class Level Variable" and the rest is very easy. Once I have added the DocumentListener to my JTextField, putted the dirty flag to true in the 3 events ChangeUpdated, etc.., how I disable enable my button? That was my original problem. Ok. Greetings David. "John McGrath [TeamB]" <ng-b@JPMcGrath.net> escribi� en el mensaje news:xn0e0954r1170y000@newsgroups.borland.com... > On 3/27/2005 at 7:52:37 AM, Davisote wrote: > >> I'm using JBuilder Enterprise 8.0.140.0 and the document is "Learning >> Java with JBuilder" Verison 4. >> In the Chapter 19, called "Building a Java Text Editor" in the Step 13: > > I do not have a copy of the JBuilder 8 documentation set, but the JBuilder > 2005 docs have a tutorial by the same name, so that is what I am looking > at. You might want to check to see that it is the same as what you are > looking at. It is available at: > > http://info.borland.com/techpubs/jbuilder/jbuilder2005/index1280x1024.html > > Select the book, "Designing Applications with JBuilder", from the combo at > the top of the page, then Chapter 11, Step 13 from the table of contents > on the left. > > > On 3/26/2005 at 6:12:52 AM, Davisote wrote: > >> > choose Expose As Class Level Variable, but this option is not enabled. > > Are you saying that "Expose As Class Level Variable" appears in the menu, > but it is disabled? I tried this with JBuilder Enterprise 8.0.140.0 and > it worked for me. If that is what you are saying, would you please post > the code that you are viewing in the UI Designer? > >> > just one of them > > I do not understand this. Just one of what? > >> > and when you select the option Regular the document option it >> > disappears. > > The property exposure level controls what properties are visible. If you > set it to "Regular", only the most commonly used properties are shown. > "Expert" shows most properties, and "Hidden" shows all properties. Since > the document property is "Expert" level, it is not shown when you set the > property exposure level to "Regular". That is how it is supposed to work. > > -- > Regards, > > John McGrath [TeamB] > > --------------------------------------------------- > Before sending me e-mail, please read: > http://www.JPMcGrath.net/newsgroups/e-mail.html
Re: Disable a button??
Author: John McGrath [TeamB]
Date: Mon, 28 Mar 2005 04:13
Date: Mon, 28 Mar 2005 04:13
16 lines
1649 bytes
1649 bytes
On 3/27/2005 at 3:46:08 PM, Davisote wrote:
> Once I have added the DocumentListener to my JTextField, putted the
> dirty flag to true in the 3 events ChangeUpdated, etc.., how I disable
> enable my button?
You use the setEnabled() method.
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Re: Disable a button??
Author: Davisote
Date: Mon, 28 Mar 2005 20:02
Date: Mon, 28 Mar 2005 20:02
23 lines
1897 bytes
1897 bytes
Thanks a lot. Everything works fine. Best Regards. DAvid "John McGrath [TeamB]" <ng-b@JPMcGrath.net> escribi� en el mensaje news:xn0e09hmbhyeci009@newsgroups.borland.com... > On 3/27/2005 at 3:46:08 PM, Davisote wrote: > >> Once I have added the DocumentListener to my JTextField, putted the >> dirty flag to true in the 3 events ChangeUpdated, etc.., how I disable >> enable my button? > > You use the setEnabled() method. > > -- > Regards, > > John McGrath [TeamB] > > --------------------------------------------------- > Before sending me e-mail, please read: > http://www.JPMcGrath.net/newsgroups/e-mail.html
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads