Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems with JDialog and useScreenMenubar option



The docs for the Mac useScreenMenuBar option indicate that a menu-less
JDialog should show its owner JFrame's JMenuBar, but the owner's menus
are never displayed (java version 1.4.2_03)
http://developer.apple.com/technotes/tn/tn2042.html#Section2_1.
To make things worse (for our palette implementation),
JDialog.setFocusableWindowState(false) doesn't prevent the JDialog from
getting the focus; the dialog gets the focus while its owner JFrame
thinks it has the focus - and still no menu bar from the owner frame.
These problems make the ScreenMenuBar pretty useless for apps with
several JDialogs for palettes, properties, and progress windows. Below
is some sample code that demonstrates both the missing menus and
mistaken focus problems (the app's only menu item toggles the dialog's
focusable window state).
Suggestions and workarounds would be greatly appreciated.

import java.awt.FlowLayout;
import java.awt.event.*;
import javax.swing.*;
public class FocusTest extends JFrame{
public JLabel frameFocusLabel = null;
public JLabel dlgFocusLabel = null;
public JCheckBoxMenuItem dlgFocusCbMenuItem = null;
public JDialog nofocusDlg = null;

public static void main(String[] args){
FocusTest ft = new FocusTest();
}
public FocusTest(){
super("Focus Test Frame");
frameFocusLabel = new JLabel();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
getContentPane().setLayout(new FlowLayout());
getContentPane().add(frameFocusLabel);
setSize(200, 200);
addFocusListener(new FocusListener(){
public void focusGained(FocusEvent e) {
frameFocusLabel.setText("Frame Gained
Focus");
}
public void focusLost(FocusEvent e) {
frameFocusLabel.setText("Frame Lost
Focus");
}
});
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
dlgFocusCbMenuItem = new JCheckBoxMenuItem("Dialog
Focusable");
dlgFocusCbMenuItem.setSelected(true);
dlgFocusCbMenuItem.addActionListener(new
ActionListener(){
public void actionPerformed(ActionEvent e) {
frameFocusLabel.setText("");
dlgFocusLabel.setText("");
if (dlgFocusCbMenuItem.isSelected())

nofocusDlg.setFocusableWindowState(true);
else

nofocusDlg.setFocusableWindowState(false);
}
});
menuBar.add(fileMenu);
fileMenu.add(dlgFocusCbMenuItem);
this.setJMenuBar(menuBar);
this.show();
nofocusDlg = new JDialog (this, "Focus Test Dialog");
nofocusDlg.setModal(false);
nofocusDlg.setSize(200, 200);
nofocusDlg.setLocation(200, 20);
dlgFocusLabel = new JLabel();
nofocusDlg.getContentPane().add(dlgFocusLabel);

nofocusDlg.addFocusListener(new FocusListener(){
public void focusGained(FocusEvent e) {
dlgFocusLabel.setText("Dialog Gained
Focus");
}
public void focusLost(FocusEvent e) {
dlgFocusLabel.setText("Dialog Lost
Focus");
}
});
nofocusDlg.show();
}
}
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Do not post admin requests to the list. They will be ignored.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.