• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JOptionPane Dialog box - JOptionPane - Dialog box - not responding to Tab keys

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
i am showing the JOptionPane confirmation dialog box for certain action in my swing application.
If i use mouse and click "YES" or "NO" , then no problem.
but if i use tab keys and make "NO" button as selected and press enter key,it always takes "YES" button action.
Is it a bug in JDK1.3 ?
*******************************************************************************
I tested the following code...............

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class demo extends Frame
{
public demo()
{
setSize(400,400);
setLocation(200,200);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
}
public static void main(String ar[])
{
demo d = new demo();

int n = JOptionPane.showConfirmDialog(d,"Would you like to Close this window ?",
"Exit Option", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null);
if(n == 0)
System.exit(0);
}
}
*****************************************************************************
Thanks,
Manikandan
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
yes , this is a bug in jdk1.3.1 .
"Yes" button is the Default button in the JOptionPane . The transfer of focus using tab key is not being reflected in JOptionPane, and this bug is not yet cleared in jdk1.4.0
keerthi
 
Manikandan Adaikkalavan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Also ,i noticed the following...
1)In Windows LAF - both "Space bar" and "Enter Key" works.
2)In Java LAF - only "Space bar" works.
Thanks,
Manikandan
 
Manikandan Adaikkalavan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
To make both the EnterKey action and SpaceBar Action to work in the dialogs...the following code will help...
UIManager.getDefaults().put("Button.focusInputMap", new
UIDefaults.LazyInputMap(new Object[] {
"ENTER", "pressed",
"released ENTER", "released","SPACE","pressed","released SPACE","released"
}));

Thanks,
Manikandan
reply
    Bookmark Topic Watch Topic
  • New Topic