Disable ESC on JOptionPane

A

Allan Valeriano

Hi all,


I'm using JOptionPane.showOptionDialog to show a dialog, but I'd like
to disable the ESC key, so when the user presses ESC, the dialog will
not close.
Is there any way to do that? Could somebody give me an example, or
give me a link showing the directions on how to do it?



thanks in advance
Allan Valeriano
 
T

Thomas Fritsch

Allan said:
I'm using JOptionPane.showOptionDialog to show a dialog, but I'd like
to disable the ESC key, so when the user presses ESC, the dialog will
not close.
The ESC key is defined to have the same effect like the Cancel button.
All users (including me) expect to be able to cancel a dialog (either by
ESC key, or by Cancel button). It would be VERY irritating if the ESC
key doesn't work, or if there is no Cancel button.
So, why on earth should you want to do that?
 
A

Allan Valeriano

The ESC key is defined to have the same effect like the Cancel button.
All users (including me) expect to be able to cancel a dialog (either by
ESC key, or by Cancel button). It would be VERY irritating if the ESC
key doesn't work, or if there is no Cancel button.
So, why on earth should you want to do that?

I'd like to do that, because this specific dialog appears only when
something goes wrong with the program, and an exception is thrown. On
this dialog, the user has the opportunity to send the developers a
message with the error and a comment about it, so I want to induce him
to do so, not just cancel it by pressing ESC.


Allan Valeriano
 
E

Eric Sosman

Allan Valeriano wrote On 02/27/07 03:49,:
I'd like to do that, because this specific dialog appears only when
something goes wrong with the program, and an exception is thrown. On
this dialog, the user has the opportunity to send the developers a
message with the error and a comment about it, so I want to induce him
to do so, not just cancel it by pressing ESC.

Don't muck up the users' controls. How would you like
it if somebody remapped your keyboard without your consent?

Instead, display this text as part of the JOptionPane's
message to the user:

!!!FREE BEER FOR A YEAR!!!

The makers of thus bug-ridden
program are so eager for your
feedback about its failure that
they have established a lottery:
Every month, one failure report
is chosen at random, and the
person who submitted it receives
!!!FREE BEER FOR A YEAR!!!

[ I WANT BEER! ] [ cancel ]

Not only will you win a lot more friends this way, but
you'll find that you have acquired a large all-volunteer
Quality Assurance department.
 
A

Allan Valeriano

Don't muck up the users' controls. How would you like
it if somebody remapped your keyboard without your consent?

Instead, display this text as part of the JOptionPane's
message to the user:

!!!FREE BEER FOR A YEAR!!!

The makers of thus bug-ridden
program are so eager for your
feedback about its failure that
they have established a lottery:
Every month, one failure report
is chosen at random, and the
person who submitted it receives
!!!FREE BEER FOR A YEAR!!!

[ I WANT BEER! ] [ cancel ]

Not only will you win a lot more friends this way, but
you'll find that you have acquired a large all-volunteer
Quality Assurance department.

Ok, you made me laugh. What about some help now?
 
C

Chris Uppal

Allan said:
Ok, you made me laugh. What about some help now?

Eric's very first sentence (quoted above) gave you all the help you need.

I.e. don't do it. It may be convenient for /you/ to disable ESC, but it is not
convenient for your users -- and they matter much more than you do.

Why not add an application option (which ***MUST*** default to false) which
means: send the report automatically unless the user explicitly asks for it not
to be sent ?

-- chris
 
E

Eric Sosman

Allan Valeriano wrote On 02/27/07 14:35,:
Don't muck up the users' controls. How would you like
it if somebody remapped your keyboard without your consent?

Instead, display this text as part of the JOptionPane's
message to the user:

!!!FREE BEER FOR A YEAR!!!

The makers of thus bug-ridden
program are so eager for your
feedback about its failure that
they have established a lottery:
Every month, one failure report
is chosen at random, and the
person who submitted it receives
!!!FREE BEER FOR A YEAR!!!

[ I WANT BEER! ] [ cancel ]

Not only will you win a lot more friends this way, but
you'll find that you have acquired a large all-volunteer
Quality Assurance department.


Ok, you made me laugh. What about some help now?

I'm serious: If you want people to do something for you,
it is more effective in the long run to coddle them than to
coerce them. Have you ever heard the saying "You can catch
more flies with honey than with vinegar?"

Now, your reward needn't be !!!FREE BEER FOR A YEAR!!!
You can reward people with all kinds of things material and
immaterial. Hanging on the wall to my right is a picture
frame holding a check from Donald E. Knuth, my reward for
spotting a trivial error in a pre-print of one of his books,
a check that cost him very little to send me (I wonder what
fraction of his reward checks ever get cashed?). You can
offer your users recognition, or your heartfealt thanks, or
a free weekend in Poughkeepsie (second prize: two weekends);
you needn't blow your budget. Be creative!

Two things to remember, though: First, you are expecting
this feedback to give you something of value, so you ought
to be willing to spend something, however little, to gain it.
Second, if you offer only tyranny the people will eventually
turn against you. Carrots, not sticks!
 
A

Allan Valeriano

Allan Valeriano wrote On 02/27/07 14:35,:


Don't muck up the users' controls. How would you like
it if somebody remapped your keyboard without your consent?
Instead, display this text as part of the JOptionPane's
message to the user:
!!!FREE BEER FOR A YEAR!!!
The makers of thus bug-ridden
program are so eager for your
feedback about its failure that
they have established a lottery:
Every month, one failure report
is chosen at random, and the
person who submitted it receives
!!!FREE BEER FOR A YEAR!!!
[ I WANT BEER! ] [ cancel ]
Not only will you win a lot more friends this way, but
you'll find that you have acquired a large all-volunteer
Quality Assurance department.
Ok, you made me laugh. What about some help now?

I'm serious: If you want people to do something for you,
it is more effective in the long run to coddle them than to
coerce them. Have you ever heard the saying "You can catch
more flies with honey than with vinegar?"

Now, your reward needn't be !!!FREE BEER FOR A YEAR!!!
You can reward people with all kinds of things material and
immaterial. Hanging on the wall to my right is a picture
frame holding a check from Donald E. Knuth, my reward for
spotting a trivial error in a pre-print of one of his books,
a check that cost him very little to send me (I wonder what
fraction of his reward checks ever get cashed?). You can
offer your users recognition, or your heartfealt thanks, or
a free weekend in Poughkeepsie (second prize: two weekends);
you needn't blow your budget. Be creative!

Two things to remember, though: First, you are expecting
this feedback to give you something of value, so you ought
to be willing to spend something, however little, to gain it.
Second, if you offer only tyranny the people will eventually
turn against you. Carrots, not sticks!

Does all of that means you guys don't know how to do that, or you're
just trying to sound like my parents? The decision about disabling the
ESC key or not is not up to me. I wouldn't do that on a personal
project, but that's not my personal project, and I HAVE to do that.
But thanks anyway.


Allan Valeriano
 
A

Andrew Thompson

Does all of that means you guys don't know how to do that, or you're
just trying to sound like my parents?

c) Attempting to prevent yet another abominable GUI.
...The decision about disabling the
ESC key or not is not up to me. I wouldn't do that on a personal
project, but that's not my personal project, and I HAVE to do that.

You always have choices. If your choice is
to continue developing an abominable GUI for
the money (fame, fortune, whatever-who-cares),
that is *your* *choice*.
But thanks anyway.

'Any time.'

Andrew T.
 
T

Thomas Fritsch

Allan said:
Does all of that means you guys don't know how to do that, or you're
just trying to sound like my parents?
I didn't want to sound like your parents.
Actually I don't know how to disable the ESC key (at least not in a
JOptionPane). With some effort it might be possible in a JDialog.
The decision about disabling the
ESC key or not is not up to me. I wouldn't do that on a personal
project, but that's not my personal project, and I HAVE to do that.
If I were you, I would tell your boss, that forcing the dialog to OK, is
likely to make your users angry, hence generating a financial
disadvantage in the long-term.

By the way: Did you ever get Microsoft's famous bug-report-dialog (after
an application-crash) asking you whether you want to send diagnostic
material to Microsoft? I use to cancel that dialog simply for security
reasons (because I don't know exactly which data would be sent).
 
E

Eric Sosman

Allan Valeriano wrote On 02/28/07 06:12,:
[...]

Does all of that means you guys don't know how to do that, or you're
just trying to sound like my parents? The decision about disabling the
ESC key or not is not up to me. I wouldn't do that on a personal
project, but that's not my personal project, and I HAVE to do that.
But thanks anyway.

It means I don't know how to do it, don't want to know
how to do it, and would resist the suggestion to do it. Oh,
yeah, it also means I like to sound like your parents. (In
light of the parental authority you seek to exert over your
users, I don't think you can object too strenuously ...)

The new piece of information you've provided is that
the idea of disabling the users' controls is not yours but
someone else's. Perhaps you might bring to his or her
notice some of the opinions expressed on this thread; the
fact that sentiment so far is *unanimous* disapproval may
provide a clue to how well the software will be accepted
when released. Or perhaps the users are a captive audience
with no power to refuse software they don't like: If so,
I'm sorry for them.

"There is nothing wrong with your television set.
Do not attempt to adjust the picture. We are
controlling the transmission. If we wish to make it
louder, we will bring up the volume. If we wish to
make it softer, we will tune it to a whisper. We
will control the horizontal. We will control the
vertical. We can roll the image; make it flutter.
We can change the focus to a soft blur or sharpen
it to crystal clarity. For the next hour, sit
quietly and we will control all that you see and
hear."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top