5035693: "Open" button should be a default one in JFileChooser under Windows XP LAF
Summary: The "Open" button was made default button of FileChooser dialog windows
Reviewed-by: loneid, peterz
--- a/jdk/src/share/classes/com/sun/java/swing/plaf/motif/MotifLookAndFeel.java Thu Jun 05 13:30:41 2008 +0400
+++ b/jdk/src/share/classes/com/sun/java/swing/plaf/motif/MotifLookAndFeel.java Fri Jun 06 13:30:20 2008 +0400
@@ -1222,9 +1222,7 @@
"FileChooser.enterFileNameLabelMnemonic", new Integer (KeyEvent.VK_N), // 'n'
"FileChooser.ancestorInputMap",
new UIDefaults.LazyInputMap(new Object[] {
- "ESCAPE", "cancelSelection",
- "ENTER", "approveSelection",
- "ctrl ENTER", "approveSelection"
+ "ESCAPE", "cancelSelection"
}),
--- a/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java Thu Jun 05 13:30:41 2008 +0400
+++ b/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java Fri Jun 06 13:30:20 2008 +0400
@@ -825,9 +825,7 @@
"ESCAPE", "cancelSelection",
"F2", "editFileName",
"F5", "refresh",
- "BACK_SPACE", "Go Up",
- "ENTER", "approveSelection",
- "ctrl ENTER", "approveSelection"
+ "BACK_SPACE", "Go Up"
}),
"FileView.directoryIcon", SwingUtilities2.makeIcon(getClass(),
--- a/jdk/src/share/classes/javax/swing/JFileChooser.java Thu Jun 05 13:30:41 2008 +0400
+++ b/jdk/src/share/classes/javax/swing/JFileChooser.java Fri Jun 06 13:30:20 2008 +0400
@@ -770,7 +770,8 @@
* @since 1.4
*/
protected JDialog createDialog(Component parent) throws HeadlessException {
- String title = getUI().getDialogTitle(this);
+ FileChooserUI ui = getUI();
+ String title = ui.getDialogTitle(this);
putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY,
title);
@@ -794,6 +795,7 @@
dialog.getRootPane().setWindowDecorationStyle(JRootPane.FILE_CHOOSER_DIALOG);
}
}
+ dialog.getRootPane().setDefaultButton(ui.getDefaultButton(this));
dialog.pack();
dialog.setLocationRelativeTo(parent);
--- a/jdk/src/share/classes/javax/swing/plaf/FileChooserUI.java Thu Jun 05 13:30:41 2008 +0400
+++ b/jdk/src/share/classes/javax/swing/plaf/FileChooserUI.java Fri Jun 06 13:30:20 2008 +0400
@@ -25,7 +25,7 @@
package javax.swing.plaf;
-import javax.swing.JFileChooser;
+import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileView;
import java.io.File;
@@ -46,4 +46,15 @@
public abstract void rescanCurrentDirectory(JFileChooser fc);
public abstract void ensureFileIsVisible(JFileChooser fc, File f);
+
+ /**
+ * Returns default button for current <code>LookAndFeel</code>.
+ * <code>JFileChooser</code> will use this button as default button
+ * for dialog windows.
+ *
+ * @since 1.7
+ */
+ public JButton getDefaultButton(JFileChooser fc) {
+ return null;
+ }
}
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java Thu Jun 05 13:30:41 2008 +0400
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java Fri Jun 06 13:30:20 2008 +0400
@@ -384,6 +384,10 @@
return null;
}
+ public JButton getDefaultButton(JFileChooser fc) {
+ return getApproveButton(fc);
+ }
+
public String getApproveButtonToolTipText(JFileChooser fc) {
String tooltipText = fc.getApproveButtonToolTipText();
if(tooltipText != null) {
--- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java Thu Jun 05 13:30:41 2008 +0400
+++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java Fri Jun 06 13:30:20 2008 +0400
@@ -853,9 +853,7 @@
"ESCAPE", "cancelSelection",
"F2", "editFileName",
"F5", "refresh",
- "BACK_SPACE", "Go Up",
- "ENTER", "approveSelection",
- "ctrl ENTER", "approveSelection"
+ "BACK_SPACE", "Go Up"
}),