windowlistener

JDialog with WindowListener - windowClosing not fired

最后都变了- 提交于 2019-12-23 12:46:37
问题 I have a class that extends JDialog that have a window listener: class MyClass extends JDialog { public MyClass() { setDefaultCloseOperation( JDialog.DO_NOTHING_ON_CLOSE ); addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.out.println("closing..."); //do something... } }); } } When i click in the X button, nothing happens. And I don't see the print of "closing..." What I am missing? 回答1: Works for me. See also this related example. import

How to close a windows explorer?

无人久伴 提交于 2019-12-23 03:37:24
问题 I have a code that uses jDesktop to open a windows explorer interface when I clicked the button LOGIN and it's working right.. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Desktop desktop = Desktop.getDesktop(); File dirToOpen; try { dirToOpen = new File("C://as//2010-0000-1"); desktop.open(dirToOpen); } catch (IOException ex) { ex.getMessage(); } catch (IllegalArgumentException iae) { System.out.println("File Not Found"); } }

Terminate running threads on JFrame close

匆匆过客 提交于 2019-12-20 23:22:18
问题 How do I invoke extra operations when the user closes a JFrame window? I have to stop existing threads. As I understand it, setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); causes the frame to be closed and its thread to be stopped. Should threads be closed after JFrame.EXIT_ON_CLOSE ? Client: static boolean TERMINATE = false; public static void main(String[] args) { // some threads created while(true) { if(TERMINATE){ // do before frame closed break; } } } private static JPanel startGUI(){

JFrame On Close Operation

随声附和 提交于 2019-12-17 19:58:43
问题 I was wondering if there is a way, by clicking on the "X", to let the program perform some code before closing the JFrame. The setDefaultCloseOperation() method takes only an integer. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 回答1: You might be interested in using a WindowListener. The WindowListener tutorial. 回答2: this.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ int i=JOptionPane.showConfirmDialog(null, "Seguro que quiere salir?"); if(i==0) System

How to capture a JFrame's close button click event?

拟墨画扇 提交于 2019-12-17 03:01:12
问题 I want to call a method confirmExit() when the red close button of the title bar of a JFrame is clicked. How can I capture that event? I'd also like to prevent the window from closing if the user chooses not to proceed. 回答1: import javax.swing.JOptionPane; import javax.swing.JFrame; /*Some piece of code*/ frame.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent windowEvent) { if (JOptionPane.showConfirmDialog(frame, "Are you

Java frame iconified issue

为君一笑 提交于 2019-12-13 03:26:13
问题 I am trying to figure out how to modify some existing code so that the console window that launches, starts out minimized as a tray icon instead of the default behavior which is to just open the window. Unfortunately I do not know Java, so I am having to just search Google and guess and check based on what code does make sense to me. I know this is asking a lot. I am trying my best to slowly pickup Java and I really appreciate the help. Could someone please read over this file and tell me if

How do I redraw things when my JFrame is restored (deiconified)?

孤街醉人 提交于 2019-12-12 04:56:27
问题 I have a very basic little JFrame with JToggleButtons and subclassed JPanels that know how to draw what I want them to draw. Selecting a button causes an oval to appear in the corresponding panel. Unselecting the buttons makes the drawings disappear. Unfortunately, minimizing (iconifying) and then restoring (deiconifying) causes any drawn shapes to disappear. So I need to trigger redrawings manually. The problem is that I can only get the redrawing done (that is, I only see it) if I show a

How to trap the Window state? [closed]

孤街浪徒 提交于 2019-12-11 06:44:08
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 8 years ago . I'd a snipped and want to know how to trap it? frame.addWindowStateListener(new WindowStateListener(){ public void windowStateChanged(WindowEvent e) {

`WindowListener` acting up, perpetual firing

对着背影说爱祢 提交于 2019-12-10 14:53:49
问题 I have an application with an abstract class that extends JDialog . The class as an abstract void onClose() , and, in the class's constructor, the following code is added: addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { onClose(); } } The event is fired when expected, but then a strange thing happens. When a concrete extension of this class has code to create a new JDialog in the onClose() method, and this JDialog 's defaultCloseOperation is JDialog

How to override windowsClosing event in JFrame

南楼画角 提交于 2019-12-06 12:22:00
问题 i'm developing a JFrame which has a button to show another JFrame. On the second JFrame i want to override WindowsClosing event to hide this frame but not close all the application. So i do like this: On second JFrame addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { formWindowClosing(evt); } }); private void formWindowClosing(java.awt.event.WindowEvent evt) { this.dispose(); } but application still close when i click x button