Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

Disable ESC on JOptionPane

Thread view: 
Allan Valeriano - 26 Feb 2007 20:05 GMT
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
Thomas Fritsch - 27 Feb 2007 00:47 GMT
> 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?

> 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?

Signature

Thomas

Allan Valeriano - 27 Feb 2007 08:49 GMT
> 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
Eric Sosman - 27 Feb 2007 17:15 GMT
Allan Valeriano wrote On 02/27/07 03:49,:
>>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
[quoted text clipped - 7 lines]
> 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.

Signature

Eric.Sosman@sun.com

Allan Valeriano - 27 Feb 2007 19:35 GMT
>     Don't muck up the users' controls.  How would you like
> it if somebody remapped your keyboard without your consent?
[quoted text clipped - 21 lines]
> --
> Eric.Sos...@sun.com

Ok, you made me laugh. What about some help now?
Chris Uppal - 27 Feb 2007 19:48 GMT
> >     Don't muck up the users' controls.
> 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
Eric Sosman - 27 Feb 2007 21:10 GMT
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?
[quoted text clipped - 20 lines]
>
> 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!

Signature

Eric.Sosman@sun.com

Allan Valeriano - 28 Feb 2007 11:12 GMT
> Allan Valeriano wrote On 02/27/07 14:35,:
>
[quoted text clipped - 47 lines]
> --
> Eric.Sos...@sun.com

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
Andrew Thompson - 28 Feb 2007 11:59 GMT
...
> 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.
Thomas Fritsch - 28 Feb 2007 12:30 GMT
>>    Two things to remember, though: First, you are expecting
>>this feedback to give you something of value, so you ought
[quoted text clipped - 4 lines]
> 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).

> But thanks anyway.

Signature

Thomas

Eric Sosman - 28 Feb 2007 18:26 GMT
Allan Valeriano wrote On 02/28/07 06:12,:
> [...]
>
[quoted text clipped - 3 lines]
> 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."

Signature

Eric.Sosman@sun.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.