-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1.7
-
x86
-
windows_nt
Name: mf23781 Date: 10/14/98
If there are 2 dialogs (JOptionPane.showMessageDialog(..)one
after the other in an application (such as what happens with
the JFileChooser example in SwingSet),when the first is dismissed,
the focus moves a component in the main app (such as JMenu or
JTabbedPane), then to the button in the dialog and then BACK to
the Component in the main app. It should remain on the button
in the dialog since that is where keyboard input is directed.
This is a SERIOUS problem for assistive technology trying to
identify and speak the correct location of where input is directed.
Here a code sample to show this.. notice you need to have
the EventQueueClass loaded via the awt.properties and the line:
AWT.EventQueueClass=com.sun.java.accessibility.util.EventQueueMonitor
If you do alt-O to get to Options menu item and then activate
the 'Use this' menu, you see the message dialog, dismiss this,
and you see the second.. check the output of where focus is to
see the problem.
/*
* FocusTest.java
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.accessibility.*;
import javax.swing.table.*;
import javax.swing.border.*;
import javax.swing.event.*;
import com.sun.java.accessibility.util.*;
import java.io.*;
/**
* <P>FocusTest is an example app that uses MenuBar
*
* @version 1.0 07/28/97
* @author Fran Brown
*/
public class FocusTest extends JPanel implements FocusListener, ActionListener{
public static int INITIAL_WIDTH = 400;
public static int INITIAL_HEIGHT = 200;
JFrame jf = new JFrame("Focustest");
BorderLayout bdl = new BorderLayout();
JTabbedPane tabbedPane;
JMenuBar menuBar = new JMenuBar();
// Create the GUI
//
public FocusTest() {
System.out.println("Starting...");
SwingEventMonitor.addFocusListener((FocusListener)this);
setLayout(bdl);
// Create a tab pane
tabbedPane = new JTabbedPane();
add(tabbedPane, BorderLayout.CENTER);
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
public void windowIconified(WindowEvent e) {System.exit(0);}
};
jf.addWindowListener(l);
JPanel logoPanel = new JPanel();
JPanel lP = new JPanel();
tabbedPane.addTab("First", null, logoPanel);
tabbedPane.addTab("Second", null, lP);
// set the Tab's AccessibleName 'cause we are using a graphic only
tabbedPane.setSelectedIndex(0);
JMenu choosers = (JMenu) menuBar.add(new JMenu("Options"));
choosers.setMnemonic('O');
JMenuItem mi = (JMenuItem) choosers.add(new JMenuItem("Option 1"));
mi = (JMenuItem) choosers.add(new JMenuItem("Use this"));
ActionListener startChooser = new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(FocusTest.this, "No file chosen");
JOptionPane.showMessageDialog(FocusTest.this, "Second - No file chosen");
}
};
mi.addActionListener(startChooser);
add("North",menuBar);
jf.getContentPane().add(this);
jf.setSize(INITIAL_WIDTH, INITIAL_HEIGHT);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
jf.setLocation(screenSize.width/2 - INITIAL_WIDTH/2,
screenSize.height/2 - INITIAL_HEIGHT/2);
jf.show();
}
static public void main(String args[]) {
new FocusTest();
}
public void focusGained(FocusEvent theEvent) {
Object o = theEvent.getSource();
if (o instanceof Component) {
System.out.println(new String("FocusTest:Focus gained.. " )+ o);
}
} // focusGained
public void focusLost(FocusEvent theEvent) {
// Do Nothing
} // focusLost
public void actionPerformed(ActionEvent e) {
int xx = JOptionPane.showConfirmDialog(FocusTest.this, "No file chosen");
JOptionPane.showMessageDialog(FocusTest.this, "Second - No file chosen");
}
}
======================================================================
Name: krT82822 Date: 05/14/99
I am trapping a focusLost event and popping a Dialog in that method.
When I pop the Dialog, the focusLost method is getting called again,
which pops a second Dialog.
Here is the code:
class LossDateListener extends FocusAdapter{
public void focusGained(FocusEvent evt)
{System.out.printnl("Focus Gained");}
public void focusLost(FocusEvent evt){
System.out.println("Focus lost");
String dateText = lossText.getText();
DateRules dateRules = new DateRules();
String status = dateRules.validateLossDate(dateText);
if(!status.equalsIgnoreCase("OK"))
JOptionPane.showMessageDialog(mainFrame, status,
"Invalid", JOptionPane.INFORMATION_MESSAGE );
}
}
I get two Focus lost messages and two Dialogs on top of each other.
When I dismiss the dialog showing on top, the focus lost method
is called again which pops another Dialog. So, I am trapped
with unstoppable dialogs.
I am running this on WinNT4.0 service pack 4 and Win98
jdk1.1.7 or jdk1.2
jfc1.1.1 or the one with jdk1.2
(Review ID: 55128)
======================================================================
- duplicates
-
JDK-4290675 Focus Management Enhancements
- Closed