windowlistener

Java: WindowAdapter windowClosed method not running

妖精的绣舞 提交于 2020-01-17 01:46:23
问题 I'm currently running this in a class that extends a JFrame. When I close the window, I don't see RAN EVENT HANDLER in the console. This is not the main window, and more than one instance of this window can exist at the same time. this.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { System.out.println("RAN EVENT HANDLER"); } }); This method is inside a method called initialiseEventHandlers() which is called in the constructor, so I'm sure the code

dispose() is not the same as setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

非 Y 不嫁゛ 提交于 2020-01-05 03:32:21
问题 I noticed that if setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) is set, closing the frame will end its Process in Task Manager, but if i implement WindowListener and manually dispose() the frame, Process will remain... probably because in new Runnable() i have something like this: new Runnable() { void run() { Jsch tunnel=new Jsch(); JFrame frame=new JFrame(); frame.addWindowListener(new WindowListener() { frame.dispose(); } ); // imagine that this is legal frame.setVisible(true); } } Anyone

Calling function on windows close

我只是一个虾纸丫 提交于 2020-01-04 07:19:14
问题 Using Java: I have a GUI built using the netbeans GUI builder. The GUI class was created by extending a jFrame public class ArduinoGUI extends javax.swing.JFrame and the GUI displayed using: java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new ArduinoGUI().setVisible(true); } } Therefore I don't have an actual frame object on which to call frame. , so how in this case can I override the windowClosed function, because I have to call a specific function to tidy up a serial

Calling function on windows close

人盡茶涼 提交于 2020-01-04 07:19:08
问题 Using Java: I have a GUI built using the netbeans GUI builder. The GUI class was created by extending a jFrame public class ArduinoGUI extends javax.swing.JFrame and the GUI displayed using: java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new ArduinoGUI().setVisible(true); } } Therefore I don't have an actual frame object on which to call frame. , so how in this case can I override the windowClosed function, because I have to call a specific function to tidy up a serial

How can I stop the closing of a Java application

十年热恋 提交于 2020-01-03 19:04:27
问题 I have a Java Desktop application and I would like when the user selects Exit to get a pop-up window that asks him if he wants to proceed with closing the application or not. I know how to make the window come up and read the user's response but what I need to know is how I can stop the application from closing (something like System.close().cancel() ). Is that possible? 回答1: Yes it is possible. After calling setDefaultCloseOperation(DO_NOTHING_ON_CLOSE) , add a WindowListener or

Infinite disappear-reappear loop in JFrame java

柔情痞子 提交于 2019-12-31 05:14:18
问题 As a succession to this post I'm running into an infinite loop that causes my computer to crash. Or, well, not quite: it seems to cause the Java window (JFrame) to keep getting focus/getting iconified and normalized infinitely. As such do not try to run the code as is . The program won't allow you to shut it down, nor can you do so via task manager. I have given a complete code example, that you can run - as is often advised. As it's a stripped-down version of an actual program, some code may

AbstractAction as WindowListener

南楼画角 提交于 2019-12-28 06:23:28
问题 I'm trying to separate function from state in my GUI application by the use of Action objects. I've been successful in using these to create menu items and buttons that have the same functionality. My problem is this: I want to have the same Action for both the 'exit' item in my menu and the close button of the frame. Currently I've been able to solve it by adding the following WindowListener to the frame: private class MainWindowListener extends WindowAdapter { @Override public void

Ask user if wants to quit via JOptionPane

早过忘川 提交于 2019-12-25 11:47:22
问题 I'm using this code to confirm the user whether wants to quit or not when he CLICKS THE RED CROSS CLOSE BUTTON OF JFrame (right upper corner) Object[] options = {"Quit, My Computing Fellow", "No, I want to Work more"}; int Answer = JOptionPane.showOptionDialog(null, "What would you like to do? ","Quit:Continue", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,options[1]); if(Answer == JOptionPane.YES_OPTION){ System.exit(0); } else if (Answer == JOptionPane.CANCEL

Java WindowClosing event not called when jFrame.setUndecorated(true) is set

会有一股神秘感。 提交于 2019-12-24 22:23:19
问题 In the following snippet the WindowClosing event is not called except if you remove one line of code to the snippet. The line of code to be removed is: jFrame.setUndecorated(true); Apparently this setUndecorated(true) method disables the WindowListener/WindowAdapter functionality. Is this normal? import java.awt.BorderLayout; import java.awt.Container; import java.awt.HeadlessException; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; import java.io

How to capture a close event in java swing

狂风中的少年 提交于 2019-12-23 21:03:43
问题 I want to capture window close(red X right top position) event. I want to display a specified window upon that window based on the event. 回答1: Register a WindowListener - specifically, use its windowClosing method: Invoked when the user attempts to close the window from the window's system menu. 回答2: You need to either implement the WindowListener interface, or register a WindowAdapter . 来源: https://stackoverflow.com/questions/8781108/how-to-capture-a-close-event-in-java-swing