RFR: 8299522: JFilechooser open button size is incorrectly shown
Alexey Ivanov
aivanov at openjdk.org
Tue Jan 10 15:09:55 UTC 2023
On Tue, 10 Jan 2023 14:11:50 GMT, Tejesh R <tr at openjdk.org> wrote:
> > I suggest handling the missing text for the Approve button if a custom dialog is used with adding a `JFileChooser` instance as component by falling back to the `Open` type.
>
> I didn't get this point ? Can you please tell me what does "falling back to the 'Open' type means?
This code
new JFileChooser().showDialog(null, null);
produces the dialog that looks like:
<img width="662" alt="JFileChooser custom dialog falls back to Open dialog" src="https://user-images.githubusercontent.com/70774172/211583355-6fed7d24-fff2-4c4b-9887-0bdd75f98930.png">
It looks exactly the same as the one created by
new JFileChooser().showOpenDialog(null);
The above code works well in the three L&F that I tested, the custom dialog behaves as if it's an open dialog and the Approve button has the text "Open".
Thus, the issue exists only if you use `setDialogType(JFileChooser.CUSTOM_DIALOG);` then add the instance of `JFileChooser` to a container such as `JFrame`.
What I meant is that you can use `openButtonText` for the Approve button if it wasn't set explicitly without creating additional properties and members. This can be achieved as simple as
diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java
index c307a138114..bf214389bda 100644
--- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java
+++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java
@@ -922,7 +922,8 @@ public class BasicFileChooserUI extends FileChooserUI {
String buttonText = fc.getApproveButtonText();
if (buttonText != null) {
return buttonText;
- } else if (fc.getDialogType() == JFileChooser.OPEN_DIALOG) {
+ } else if (fc.getDialogType() == JFileChooser.OPEN_DIALOG
+ || fc.getDialogType() == JFileChooser.CUSTOM_DIALOG) {
return openButtonText;
} else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG) {
return saveButtonText;
-------------
PR: https://git.openjdk.org/jdk/pull/11901
More information about the client-libs-dev
mailing list