5035693: "Open" button should be a default one in JFileChooser under Windows XP LAF

The "Open" button was made default button of FileChooser dialog windows

Reviewed-by: loneid, peterz
This commit is contained in:
Pavel Porvatov 2008-06-06 13:30:20 +04:00
parent 9a2ae13639
commit 8f7aabf955
6 changed files with 22 additions and 11 deletions

View File

@ -1222,9 +1222,7 @@ public class MotifLookAndFeel extends BasicLookAndFeel
"FileChooser.enterFileNameLabelMnemonic", new Integer (KeyEvent.VK_N), // 'n'
"FileChooser.ancestorInputMap",
new UIDefaults.LazyInputMap(new Object[] {
"ESCAPE", "cancelSelection",
"ENTER", "approveSelection",
"ctrl ENTER", "approveSelection"
"ESCAPE", "cancelSelection"
}),

View File

@ -825,9 +825,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel
"ESCAPE", "cancelSelection",
"F2", "editFileName",
"F5", "refresh",
"BACK_SPACE", "Go Up",
"ENTER", "approveSelection",
"ctrl ENTER", "approveSelection"
"BACK_SPACE", "Go Up"
}),
"FileView.directoryIcon", SwingUtilities2.makeIcon(getClass(),

View File

@ -770,7 +770,8 @@ public class JFileChooser extends JComponent implements Accessible {
* @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 @@ public class JFileChooser extends JComponent implements Accessible {
dialog.getRootPane().setWindowDecorationStyle(JRootPane.FILE_CHOOSER_DIALOG);
}
}
dialog.getRootPane().setDefaultButton(ui.getDefaultButton(this));
dialog.pack();
dialog.setLocationRelativeTo(parent);

View File

@ -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 class FileChooserUI extends ComponentUI
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;
}
}

View File

@ -384,6 +384,10 @@ public class BasicFileChooserUI extends FileChooserUI {
return null;
}
public JButton getDefaultButton(JFileChooser fc) {
return getApproveButton(fc);
}
public String getApproveButtonToolTipText(JFileChooser fc) {
String tooltipText = fc.getApproveButtonToolTipText();
if(tooltipText != null) {

View File

@ -853,9 +853,7 @@ public class MetalLookAndFeel extends BasicLookAndFeel
"ESCAPE", "cancelSelection",
"F2", "editFileName",
"F5", "refresh",
"BACK_SPACE", "Go Up",
"ENTER", "approveSelection",
"ctrl ENTER", "approveSelection"
"BACK_SPACE", "Go Up"
}),