3

On javadoc, the HIDE_ON_CLOSE default option says that

Automatically hide the frame after invoking any registered WindowListener objects.

Now what it means "HIDE"? the realtive object is destroyed or just hide and continue using resources?

giozh
  • 8,808
  • 27
  • 89
  • 163
  • Hide basically means it won't destroy the native reource/peer that it is attached to, normally making it faster to redisplay, because it doesn't need to create the native peer. Dispose on the other hand will (destroy the native peer). So if you don't need to redisplay the frame often, use DISPOSE_ON_CLOSE, otherwise, use hide – MadProgrammer Jul 19 '13 at 10:28

3 Answers3

6

On javadoc, the HIDE_ON_CLOSE default option says that

Automatically hide the frame after invoking any registered WindowListener objects.

Now what it means "HIDE"? the realtive object is destroyed or just hide and continue using resources?

  • HIDE_ON_CLOSE is the same as JFrame.setVisible(false),

  • then JFrame in only hiden, invisible, isn't destroyed somehow (the same for JFrame.dispose()), by JFrame.setVisible(true) is again visible on the sceen and without any changes

EDIT

@giozh wrote and if i want to destroy the jframe (without close the entire application)?

  1. by default there isn't any reason, because by default there no reason to create another JFrame, don't do that, use CardLayout (with JFrame.pack() if is neccessary to change JFrames size on the screen)

  2. and all those Object stays and increasing JVM memory, never will be CG'ed, then there isn't siginficant difference for JVM memory between JFrame.HIDE_ON_CLOSE, JFrame.DISPOSE_ON_CLOSE or JFrame.setVisible(false)

  3. (in the casse that you hate CardLayout) you can to remove all JComponents from JFrames ContentPane, then to add new JComponents, set LayoutManager and last code lines (after all changes to the already visible JFrame is done) would be JFrame.(re)validate();, JFrame.repaint(); and JFrame.pack();

Community
  • 1
  • 1
mKorbel
  • 108,320
  • 17
  • 126
  • 296
  • and if i want to destroy the jframe (without close the entire application)? – giozh Jul 19 '13 at 10:15
  • Could you tell me an advantage of this? I mean if I close the window and it hides my frame how would I make it visible again? – Makky Jul 19 '13 at 10:15
  • @giozh use DISPOSE_ON_CLOSE – Makky Jul 19 '13 at 10:16
  • because the JFrame that i would close it's not main Jframe, but a secondary one opened for execute some operation on user request – giozh Jul 19 '13 at 10:19
  • thanks for reply, but cardlayout isn't what i'm looking for. I would an indipendent component (a sort of popup) for take some input to compute. – giozh Jul 19 '13 at 10:25
  • then see my point (edit) 3rd., stil I don't understant, create JFrame as local variable, then is accesible from all corners of JVM, only to switch betweens view (by add/remove JComponents or CardLayout), CardLayout is easiest than endless pop_up a new JFrames Objects on the Screen, and a new JFrame flickering with Borders, CardLayout never – mKorbel Jul 19 '13 at 10:28
  • `I would an indipendent component (a sort of popup) for take some input to compute.` not sure if you meaning popup windos aka some notificaion or message box, to use JDialog, maybe undecorated, one JDialog, reuse this JDialog setVisible(false/true), set repeatly only value to JComponents, if there are a few views, then CarLayout is best of ways – mKorbel Jul 19 '13 at 10:36
0

hide it in background without destroying it, keep it in memory

  • Not an answer but a comment. Post this as comment. – Makky Jul 19 '13 at 10:13
  • @Makky: how would he post this as a comment, he doesn't have +50 points! So please remove your downvote. – Azad Jul 19 '13 at 10:18
  • Then he should post a proper answer. This is not an answer and deserver downvote unless this guys edits it back with more information. – Makky Jul 19 '13 at 10:23
  • @Makky: Yes, there is a lack of information, but still don't need to downvote as it's not wrong! – Azad Jul 19 '13 at 10:27
  • Incomplete answers are usually downvoted so a user could edit it and give a proper answer. – Makky Jul 19 '13 at 10:28
0

HIDE_ON_CLOSE means that it will just disppear but will be running in the background and consuming resources ,though not visible on the screen.

But using EXIT_ON_CLOSE,instead,makes it disappear as well as kills the application (Use this if you want to really close the application)

Insane Coder
  • 6,859
  • 11
  • 62
  • 140