 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Luc Van Bogaert Guest
|
Posted: Fri Apr 29, 2005 9:43 am Post subject: Problem handling events on a JCombobox |
|
|
Hi,
I'm using an editable JComboBox to start a search on a database
table. In some cases, the combobox generates two action events (after
Enter, and after a selection change) How can I avoid to process the
same actionevent code (my search routine) twice?
Thanks!
--
Luc Van Bogaert (E-mail ROT13'ed)
|
|
| Back to top |
|
 |
Knute Johnson Guest
|
Posted: Sat Apr 30, 2005 3:50 pm Post subject: Re: Problem handling events on a JCombobox |
|
|
Luc Van Bogaert wrote:
| Quote: | Hi,
I'm using an editable JComboBox to start a search on a database
table. In some cases, the combobox generates two action events (after
Enter, and after a selection change) How can I avoid to process the
same actionevent code (my search routine) twice?
Thanks!
|
Luc:
The JComboBox produces ActionEvents on two different actions. One is
caused by selecting a new item the other by editing the field. Run my
little program below and you will see. If you call
setActionCommand("something") on the box that only effects the
ActionEvent that is fired when a different item is selected not when you
edit and/or press Enter in the editable part of the field. So if you
don't want the event that is caused by pressing Enter throw away the
event with the action command "comboBoxEdited".
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test3 {
public static void main(String[] args) {
String[] items = {"item1","item2","item3"};
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JComboBox b = new JComboBox(items);
b.setEditable(true);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String ac = ae.getActionCommand();
System.out.println(ac);
}
});
f.add(b);
f.pack();
f.setVisible(true);
}
}
--
Knute Johnson
email s/nospam/knute/
|
|
| Back to top |
|
 |
Luc Van Bogaert Guest
|
Posted: Sun May 01, 2005 10:49 am Post subject: Re: Problem handling events on a JCombobox |
|
|
On Sat, 30 Apr 2005 15:50:29 UTC, Knute Johnson
<nospam (AT) sagebrush (DOT) frazmtn.com> wrote:
| Quote: | The JComboBox produces ActionEvents on two different actions. One is
caused by selecting a new item the other by editing the field. Run my
little program below and you will see. If you call
setActionCommand("something") on the box that only effects the
ActionEvent that is fired when a different item is selected not when you
edit and/or press Enter in the editable part of the field. So if you
don't want the event that is caused by pressing Enter throw away the
event with the action command "comboBoxEdited".
|
Thank you, this solved my little problem. I do have another question
for you about the JComboBox, if you don't mind :
When I bring up the combobox to let the user enter or select a search
string, I'd like to put the focus in the editiable field of the
combobox, but it seems that a call to requestFocus(), just puts the
focus on the little arrow widget of the combobox, and not in the
textfield itself. Do you know a way to solve this?
Thanks!
--
Luc Van Bogaert (E-mail ROT13'ed)
|
|
| Back to top |
|
 |
Knute Johnson Guest
|
Posted: Sun May 01, 2005 2:53 pm Post subject: Re: Problem handling events on a JCombobox |
|
|
Luc Van Bogaert wrote:
| Quote: | On Sat, 30 Apr 2005 15:50:29 UTC, Knute Johnson
[email]nospam (AT) sagebrush (DOT) frazmtn.com[/email]> wrote:
The JComboBox produces ActionEvents on two different actions. One is
caused by selecting a new item the other by editing the field. Run my
little program below and you will see. If you call
setActionCommand("something") on the box that only effects the
ActionEvent that is fired when a different item is selected not when you
edit and/or press Enter in the editable part of the field. So if you
don't want the event that is caused by pressing Enter throw away the
event with the action command "comboBoxEdited".
Thank you, this solved my little problem. I do have another question
for you about the JComboBox, if you don't mind :
When I bring up the combobox to let the user enter or select a search
string, I'd like to put the focus in the editiable field of the
combobox, but it seems that a call to requestFocus(), just puts the
focus on the little arrow widget of the combobox, and not in the
textfield itself. Do you know a way to solve this?
Thanks!
|
Luc:
I can't duplicate that problem with 1.5.0_03 on Winblows XP. With my
little test program that I posted yesterday, the cursor is at the
beginning of the editable part of the JComboBox field. What operating
system are you using? Can you post a short test program?
--
Knute Johnson
email s/nospam/knute/
|
|
| Back to top |
|
 |
Luc Van Bogaert Guest
|
Posted: Mon May 02, 2005 1:58 pm Post subject: Re: Problem handling events on a JCombobox |
|
|
On Sun, 1 May 2005 14:53:11 UTC, Knute Johnson
<nospam (AT) sagebrush (DOT) frazmtn.com> wrote:
| Quote: | I can't duplicate that problem with 1.5.0_03 on Winblows XP. With my
little test program that I posted yesterday, the cursor is at the
beginning of the editable part of the JComboBox field. What operating
system are you using? Can you post a short test program?
|
I'm running Java 1.4.1_07 on eComStation, which is an OS/2
distribution. Your demo program runs fine here as well, with the focus
in the edit field. I think I'll have to take another look at my code.
Thanks,
--
Luc Van Bogaert (E-mail ROT13'ed)
|
|
| Back to top |
|
 |
Knute Johnson Guest
|
Posted: Mon May 02, 2005 3:17 pm Post subject: Re: Problem handling events on a JCombobox |
|
|
Luc Van Bogaert wrote:
| Quote: | On Sun, 1 May 2005 14:53:11 UTC, Knute Johnson
[email]nospam (AT) sagebrush (DOT) frazmtn.com[/email]> wrote:
I can't duplicate that problem with 1.5.0_03 on Winblows XP. With my
little test program that I posted yesterday, the cursor is at the
beginning of the editable part of the JComboBox field. What operating
system are you using? Can you post a short test program?
I'm running Java 1.4.1_07 on eComStation, which is an OS/2
distribution. Your demo program runs fine here as well, with the focus
in the edit field. I think I'll have to take another look at my code.
Thanks,
|
Luc:
How do you like the eComStation OS/2? I used to do a lot of work under
OS/2 but when it stopped being updated we moved on to other
environments. A few years ago I thought OS/2 was the most stable and
best multitasking operating system around for PCs. We had some code
that ran almost 10 years under several different versions of OS/2.
When I found Java there was little or no support for it on OS/2 so we
migrated back to Winblows. The reduced development time for Java and
the ease of writing multithreaded apps with Java made it a pretty easy
decision.
--
Knute Johnson
email s/nospam/knute/
|
|
| Back to top |
|
 |
Luc Van Bogaert Guest
|
Posted: Mon May 02, 2005 4:43 pm Post subject: Re: Problem handling events on a JCombobox (OT) |
|
|
On Mon, 2 May 2005 15:17:27 UTC, Knute Johnson
<nospam (AT) sagebrush (DOT) frazmtn.com> wrote:
| Quote: | Luc:
How do you like the eComStation OS/2? I used to do a lot of work under
OS/2 but when it stopped being updated we moved on to other
environments. A few years ago I thought OS/2 was the most stable and
best multitasking operating system around for PCs. We had some code
that ran almost 10 years under several different versions of OS/2.
When I found Java there was little or no support for it on OS/2 so we
migrated back to Winblows. The reduced development time for Java and
the ease of writing multithreaded apps with Java made it a pretty easy
decision.
|
I've been using OS/2 and later eComStation for my own private use for
many years, starting in 1993 with Warp 3, and up until now I haven't
found a good reason to switch to something else, so I will continue
using it as long as it serves my needs. eComStation (made under OEM
contract by Serenity Systems) is updated quite regularly and will
support most modern hardware. A new 2.0 release has already been
announced. See www.ecomstation.com for more information.
With respect to Java, OS/2 has had a rather remarkable history : it
was the very first OS to ship with an integrated Java environment, but
then it got a somewhat behind just at the moment when Java seemed to
take off Nowadays, there's decent support for Java under OS/2. IBM
still supports an their older 1.3 release, but there are two companies
that provide a 1.4.x release : Innotek has a freeware product, and
Golden Code has a commercial offering, which is the one I am running.
As for IDE's, pure Java apps are the only option on OS/2.
--
Luc Van Bogaert (E-mail ROT13'ed)
http://www.os2world.com/os2ecs
|
|
| Back to top |
|
 |
Knute Johnson Guest
|
Posted: Tue May 03, 2005 2:54 am Post subject: Re: Problem handling events on a JCombobox (OT) |
|
|
Luc Van Bogaert wrote:
| Quote: | On Mon, 2 May 2005 15:17:27 UTC, Knute Johnson
[email]nospam (AT) sagebrush (DOT) frazmtn.com[/email]> wrote:
Luc:
How do you like the eComStation OS/2? I used to do a lot of work under
OS/2 but when it stopped being updated we moved on to other
environments. A few years ago I thought OS/2 was the most stable and
best multitasking operating system around for PCs. We had some code
that ran almost 10 years under several different versions of OS/2.
When I found Java there was little or no support for it on OS/2 so we
migrated back to Winblows. The reduced development time for Java and
the ease of writing multithreaded apps with Java made it a pretty easy
decision.
I've been using OS/2 and later eComStation for my own private use for
many years, starting in 1993 with Warp 3, and up until now I haven't
found a good reason to switch to something else, so I will continue
using it as long as it serves my needs. eComStation (made under OEM
contract by Serenity Systems) is updated quite regularly and will
support most modern hardware. A new 2.0 release has already been
announced. See www.ecomstation.com for more information.
With respect to Java, OS/2 has had a rather remarkable history : it
was the very first OS to ship with an integrated Java environment, but
then it got a somewhat behind just at the moment when Java seemed to
take off Nowadays, there's decent support for Java under OS/2. IBM
still supports an their older 1.3 release, but there are two companies
that provide a 1.4.x release : Innotek has a freeware product, and
Golden Code has a commercial offering, which is the one I am running.
As for IDE's, pure Java apps are the only option on OS/2.
|
Thanks Luc I'll have to give eComStation a try.
--
Knute Johnson
email s/nospam/knute/
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|