This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Manikandan Adaikkalavan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • 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
 
keerthi matta
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!