简体   繁体   中英

JFileChooser with no textArea

I'm maybe just missing something very simple but I'm unable to display a text area on the JFileChooser that I created and I unable to find the solution to this problem over the Internet. I would precise that I'm working on OSX and already tried setDialogType .

I'm still stucked with this UI:

在此处输入图片说明

I really need the textarea (to set filename) and it'll be better if I could keep the OSX-like UI.

To be more precise, I'd to add the red textarea of this picture:

在此处输入图片说明

Try setting the type to SAVE_DIALOG . This will give you the text field that you want (the difference between OPEN_DIALOG and SAVE_DIALOG is entirely cosmetic). You will want to manually override the text of the title bar and save button to read "open" in order to make it clear to the user what the dialog box is for. You will also need to implement something to do in case the user enters a file name that does not exist.

So, I solved the bug by changing the UI style and I've to concede that I'm not very happy with this kind of resolution but it's two lines of code and should not introduce any bug; just break a bit the workflow I designed. It's still the best for minimal changes; if you don't wanna to do this, I guess that you could build you own dialog but requires much more time.

I let the "magical" code there:

    try {
        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (Exception e) {
        // If you got no chance ;)
    }

EDIT:

I made a mistake and used the wrong method. I used showOpenDialog(Component parent) instead of showDialog(Component parent, String approveButtonTitle) . At the end you can have what you want by writting something like this:

JFileChooser fc = new JFileChooser();
String title = isLoad ? "Load the game" : "Save the game";
int type = isLoad ? JFileChooser.OPEN_DIALOG:JFileChooser.SAVE_DIALOG;
fc.setDialogType(type);
fc.showDialog(null, title);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM