disposing

Anonymous event handlers and disposing

独自空忆成欢 提交于 2020-01-13 02:47:20
问题 I have a rather short question about anonymous event handlers: This is the code that I have : public void AddTestControl(Control ctrl) { ctrl.Disposed += (o, e) => { RemoveTestControl(ctrl); }; ctrl.SomeEvent += _Control_SomeEvent; } public void RemoveTestControl(Control ctrl) { ctrl.SomeEvent -= _Control_SomeEvent; } Is this code above fine, or should the code be rewritten in order to remove the Disposed Event Handler? Something like this: public void AddTestControl(Control ctrl) { ctrl

Disposing JFrame by clicking from an inner JPanel

天大地大妈咪最大 提交于 2019-12-18 09:33:48
问题 I'm trying to dispose my JFrame by clicking a button, located on a JPanel that is placed on the JFrame that I want to close. I tried to make a static method on the JFrame class, but ofcourse my IDE told me that wasn't going to happen. Anyone thinking of a solution? Thanks! 回答1: Try this: public class DisposeJFrame extends JFrame{ JPanel panel = new JPanel(); JButton button = new JButton("Dispose JFrame"); public DisposeJFrame(){ super(); setTitle("Hi"); panel.add(button); add(panel); pack();

Right way of using Backgroundworker

雨燕双飞 提交于 2019-12-12 10:17:59
问题 I'm using a backgroundworker for showing a loadingscreen. The DO-event looks as follow: private void bwLoadingScreen_DoWork(object sender, DoWorkEventArgs e) { _ls = new LoadingScreen(); _ls.Show(); while (!bwLoadingScreen.CancellationPending) { Application.DoEvents(); } } I use the following code to Dispose the Loadingscreen: if (_ls.InvokeRequired && !_ls.IsDisposed) { Invoke(new MethodInvoker(delegate { _ls.Close(); _ls.Dispose(); })); } else if (!_ls.IsDisposed) { _ls.Hide(); _ls.Dispose(

Right way of using Backgroundworker

纵然是瞬间 提交于 2019-12-08 19:24:26
I'm using a backgroundworker for showing a loadingscreen. The DO-event looks as follow: private void bwLoadingScreen_DoWork(object sender, DoWorkEventArgs e) { _ls = new LoadingScreen(); _ls.Show(); while (!bwLoadingScreen.CancellationPending) { Application.DoEvents(); } } I use the following code to Dispose the Loadingscreen: if (_ls.InvokeRequired && !_ls.IsDisposed) { Invoke(new MethodInvoker(delegate { _ls.Close(); _ls.Dispose(); })); } else if (!_ls.IsDisposed) { _ls.Hide(); _ls.Dispose(); } Should I use the RunWorkerCompleted event for this? Is this the right way to use the

JavaFX IllegalStateException when disposing JFXPanel in Swing

杀马特。学长 韩版系。学妹 提交于 2019-11-30 12:26:00
I've just come across an oddity with JavaFX and Swing. When disposing a JavaFX Panel that had been added to a JFrame or JPanel, re-adding a new JFXPanel will throw an IllegalStateException: "Platform.exit has been called". In my case this has happened after I removed some JPanels with JFXPanels inside and then tried to re-add them. Luckily I found a solution in an Oracle Forum. Link: https://kr.forums.oracle.com/forums/thread.jspa?threadID=2393986 In JavaFX 2.2 add the following line in the Main class: Platform.setImplicitExit(false); This has done the trick in my application and will

JavaFX IllegalStateException when disposing JFXPanel in Swing

爷,独闯天下 提交于 2019-11-29 17:49:17
问题 I've just come across an oddity with JavaFX and Swing. When disposing a JavaFX Panel that had been added to a JFrame or JPanel, re-adding a new JFXPanel will throw an IllegalStateException: "Platform.exit has been called". In my case this has happened after I removed some JPanels with JFXPanels inside and then tried to re-add them. 回答1: Luckily I found a solution in an Oracle Forum. Link: https://kr.forums.oracle.com/forums/thread.jspa?threadID=2393986 In JavaFX 2.2 add the following line in

Disposing JFrame by clicking from an inner JPanel

♀尐吖头ヾ 提交于 2019-11-29 16:25:45
I'm trying to dispose my JFrame by clicking a button, located on a JPanel that is placed on the JFrame that I want to close. I tried to make a static method on the JFrame class, but ofcourse my IDE told me that wasn't going to happen. Anyone thinking of a solution? Thanks! Try this: public class DisposeJFrame extends JFrame{ JPanel panel = new JPanel(); JButton button = new JButton("Dispose JFrame"); public DisposeJFrame(){ super(); setTitle("Hi"); panel.add(button); add(panel); pack(); button.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) {