Java Swing: How to keep parent window open after closing JFileChooser

just_a_programmer

After opening a JFileChooser from a button in a window, the File Chooser opens, then the original window closes. I would like to keep that original window open throughout when the user is using the File Chooser and after.

My code:

// Code from the class that makes the original window that has the launch button
FilePicker filePicker = new FilePicker();
public void actionPerformed(ActionEvent e) {
            txtImportLog.append("\nUser selecting file");
            if (filePicker.canPick()) {
            filePicker.init();
            filePicker.getImportFile();
            } else {
                txtImportLog.append("\nCan't pick more files.");
            }
        }
    }); 

// Code from the class that creates a FilePicker 
//(yes, I know the getImportFile() and init() methods are setup badly, its just for
// testing right now
// Initialize - only should be called once
public void init() {
    filePicker = new JFileChooser();
    interval1 = 0;
    interval2 = 0;
    testFile = new File(""); // for testing. clearly.
}

// Get a file to import
public static File getImportFile() {
    filePicker.setFileSelectionMode(JFileChooser.FILES_ONLY);
    filePicker.showOpenDialog(filePicker);
    return filePicker.getSelectedFile();

}
just_a_programmer

Oops, I simply had code (auto-generated by Eclipse plug-in WindowBuilder) that looked for when the parent window lost focus, it would close the application. The file chooser's parent was the main window. So when the user clicked the "Open file chooser" button, focus of the main window would be lost, closing the application.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to keep skype-wrapper in messaging menu after closing it?

분류에서Dev

Keep Application running after Closing Event in WPF

분류에서Dev

Closing a window after the page is fully loaded

분류에서Dev

In qlikview , Is it possible to keep the script window always open?

분류에서Dev

How to keep the window open: ShellExecuteW(0,0,"powershell.exe", "..","..",SW_SHOW)?

분류에서Dev

How to keep java.awt.List from covering javax.swing.JMenu

분류에서Dev

Java ScriptEngine and parent window functions

분류에서Dev

app is closing after going back to main window / c++

분류에서Dev

Python: HSQL DB remains open after closing? (jaydebeapi)

분류에서Dev

Photoshop CS6 not releasing memory after closing open files

분류에서Dev

How can I keep mega sub menu open after mouse leaves top navigation button?

분류에서Dev

How to keep window always on active workspace?

분류에서Dev

How do I keep a notification open in firefox?

분류에서Dev

How can I open a terminal window on OSX?

분류에서Dev

Google Maps, open info window after click on a link

분류에서Dev

How to embed JavaFX SimpleSwingBrowser in Java swing

분류에서Dev

How to open a vpn channel (interactively) and keep the vpn session in background

분류에서Dev

How to show window after pressing X

분류에서Dev

Cancelling window closing with a task. How can I detect if task returned synchronously?

분류에서Dev

How to create custom google chrome extension for new window And keep focus the new window in alternative click of extension

분류에서Dev

How can "git gui" open repository from parent directory?

분류에서Dev

In Xcode how do I get files to open in the same window

분류에서Dev

How to create chrome profile desktop shortcut that will not open in new chrome window?

분류에서Dev

How to open new window browser when user click close tab?

분류에서Dev

How can I open a popup window to alarm user and running in background?

분류에서Dev

How to make a window not open when the app loads XCode

분류에서Dev

How do you open a new JPanel window on a click of a button?

분류에서Dev

How do I get websites and software applications to open up into a window?

분류에서Dev

How to keep a Java program secure from hacking

Related 관련 기사

  1. 1

    How to keep skype-wrapper in messaging menu after closing it?

  2. 2

    Keep Application running after Closing Event in WPF

  3. 3

    Closing a window after the page is fully loaded

  4. 4

    In qlikview , Is it possible to keep the script window always open?

  5. 5

    How to keep the window open: ShellExecuteW(0,0,"powershell.exe", "..","..",SW_SHOW)?

  6. 6

    How to keep java.awt.List from covering javax.swing.JMenu

  7. 7

    Java ScriptEngine and parent window functions

  8. 8

    app is closing after going back to main window / c++

  9. 9

    Python: HSQL DB remains open after closing? (jaydebeapi)

  10. 10

    Photoshop CS6 not releasing memory after closing open files

  11. 11

    How can I keep mega sub menu open after mouse leaves top navigation button?

  12. 12

    How to keep window always on active workspace?

  13. 13

    How do I keep a notification open in firefox?

  14. 14

    How can I open a terminal window on OSX?

  15. 15

    Google Maps, open info window after click on a link

  16. 16

    How to embed JavaFX SimpleSwingBrowser in Java swing

  17. 17

    How to open a vpn channel (interactively) and keep the vpn session in background

  18. 18

    How to show window after pressing X

  19. 19

    Cancelling window closing with a task. How can I detect if task returned synchronously?

  20. 20

    How to create custom google chrome extension for new window And keep focus the new window in alternative click of extension

  21. 21

    How can "git gui" open repository from parent directory?

  22. 22

    In Xcode how do I get files to open in the same window

  23. 23

    How to create chrome profile desktop shortcut that will not open in new chrome window?

  24. 24

    How to open new window browser when user click close tab?

  25. 25

    How can I open a popup window to alarm user and running in background?

  26. 26

    How to make a window not open when the app loads XCode

  27. 27

    How do you open a new JPanel window on a click of a button?

  28. 28

    How do I get websites and software applications to open up into a window?

  29. 29

    How to keep a Java program secure from hacking

뜨겁다태그

보관