13 Replies - 508 Views - Last Post: 17 July 2019 - 01:06 PM Rate Topic: -----

#1 dako   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 01-July 19

Closing my visible JFrame without closing my main application window.

Posted 15 July 2019 - 09:44 PM

I have set visible a JFrame class that my application window can access to manage data. But when I am done managing the data, and I cancel out of the JFrame class, it also closes my application window. Could you please tell me how to prevent this from happening?
Is This A Good Question/Topic? 0
  • +

Replies To: Closing my visible JFrame without closing my main application window.

#2 wseng92   User is offline

  • D.I.C Addict
  • member icon

Reputation: 50
  • View blog
  • Posts: 691
  • Joined: 23-September 15

Re: Closing my visible JFrame without closing my main application window.

Posted 15 July 2019 - 09:51 PM

Maybe show us your code?
Was This Post Helpful? 0
  • +
  • -

#3 dako   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 01-July 19

Re: Closing my visible JFrame without closing my main application window.

Posted 15 July 2019 - 10:01 PM

View Postwseng92, on 15 July 2019 - 09:51 PM, said:

Maybe show us your code?


Sorry, people keep asking that. I guess it's a standard thing.

Okay here's the code:

JButton btnManageData = new JButton("Manage Data");
		btnManageData.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				
				obj.setVisible(true);
				
				
			}
		});
		btnManageData.setBounds(159, 220, 122, 21);
		frmDatabaseConnector.getContentPane().add(btnManageData);
		
		JButton btnDelete = new JButton("Delete");
		btnDelete.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
			}
		}); 


And what happens is when the second window pops up, it will let me do what it is suppose to. But when I close the second window, bam the main window goes away to.
Was This Post Helpful? 0
  • +
  • -

#4 wseng92   User is offline

  • D.I.C Addict
  • member icon

Reputation: 50
  • View blog
  • Posts: 691
  • Joined: 23-September 15

Re: Closing my visible JFrame without closing my main application window.

Posted 15 July 2019 - 11:16 PM

What is obj? Can you post obj code as well?
Was This Post Helpful? 0
  • +
  • -

#5 chanjul   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 66
  • Joined: 11-September 18

Re: Closing my visible JFrame without closing my main application window.

Posted 16 July 2019 - 12:08 AM

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

hope this help.
if you are using netbeans
just check the properties
there is option "defaultCloseOperation" and there is option like : hide, exit on close, dispose and do nothing.
just choose between that and it will set automatically (if you are using netbeans) hide means the frame will be hidden, exit on close means when you press X button it will exit the system entirely, do nothing means the X button will not do anything even you press it and dispose means when you press x button it will only close the frame but not close the entire application
Was This Post Helpful? 1
  • +
  • -

#6 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3639
  • View blog
  • Posts: 16,716
  • Joined: 20-September 08

Re: Closing my visible JFrame without closing my main application window.

Posted 16 July 2019 - 01:58 AM

JFrames are only meant to be used one per application normally. If you want to show another window, use something like JDialog and set the JFrame as its parent
Was This Post Helpful? 0
  • +
  • -

#7 dako   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 01-July 19

Re: Closing my visible JFrame without closing my main application window.

Posted 17 July 2019 - 07:23 AM

View Postchanjul, on 16 July 2019 - 12:08 AM, said:

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

hope this help.
if you are using netbeans
just check the properties
there is option "defaultCloseOperation" and there is option like : hide, exit on close, dispose and do nothing.
just choose between that and it will set automatically (if you are using netbeans) hide means the frame will be hidden, exit on close means when you press X button it will exit the system entirely, do nothing means the X button will not do anything even you press it and dispose means when you press x button it will only close the frame but not close the entire application

Yeah bro this was perfect. I wasn't really sure where to put it haha but apparently I picked the right spot because it did exactly what I was hoping for. Thank you so much.
Was This Post Helpful? 0
  • +
  • -

#8 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3639
  • View blog
  • Posts: 16,716
  • Joined: 20-September 08

Re: Closing my visible JFrame without closing my main application window.

Posted 17 July 2019 - 07:42 AM

If you use the correct kind of window (see above) you don't have to write any code to deal with its closing behaviour
Was This Post Helpful? 0
  • +
  • -

#9 dako   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 01-July 19

Re: Closing my visible JFrame without closing my main application window.

Posted 17 July 2019 - 07:45 AM

View Postg00se, on 17 July 2019 - 07:42 AM, said:

If you use the correct kind of window (see above) you don't have to write any code to deal with its closing behaviour


Idk man like I've said in almost all my threads I am a complete beginner. I am watching videos on youtube and this is what they showed me. No one is taking to time for fully explain stuff so even though I am fairly positive you are right, I don't know how to implement a JDialog. It may be the exact same, but once again I am just exploring and trying to figure out how it all works and for now the DISPOSE_ON_EXIT() worked pretty dandy.
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15160
  • View blog
  • Posts: 60,694
  • Joined: 12-June 08

Re: Closing my visible JFrame without closing my main application window.

Posted 17 July 2019 - 07:46 AM

I am certain this has been suggested, but instead of cherry picking videos of unknown quality - pick up a book on the language you are using and go through it. Structured learning is better than stumbling around in the dark.
Was This Post Helpful? 0
  • +
  • -

#11 dako   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 01-July 19

Re: Closing my visible JFrame without closing my main application window.

Posted 17 July 2019 - 12:50 PM

View Postmodi123_1, on 17 July 2019 - 07:46 AM, said:

I am certain this has been suggested, but instead of cherry picking videos of unknown quality - pick up a book on the language you are using and go through it. Structured learning is better than stumbling around in the dark.

I'm sure it is but I work 13 hours a week so that when college starts next year I can afford it and I want some hands on experience before I begin the official studies. So that is what I am trying to do now.
Was This Post Helpful? 0
  • +
  • -

#12 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15160
  • View blog
  • Posts: 60,694
  • Joined: 12-June 08

Re: Closing my visible JFrame without closing my main application window.

Posted 17 July 2019 - 12:54 PM

Ease up on the rep system sport; I suggest perusing the FAQ.

To clarify what I am saying - expecting people to hand hold you through absolute zero to some understanding, with an undefined level ground level info, is a little much. Videos inherently have an issue of cherry picking topics and missing the good mortar that binds the bricks. The way to get that end-to-end information is to either take a long class or buy a book on the topic and work through it. Structured learning is preferable than flailing around with disconnected videos.
Was This Post Helpful? 1
  • +
  • -

#13 dako   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 01-July 19

Re: Closing my visible JFrame without closing my main application window.

Posted 17 July 2019 - 12:58 PM

View Postmodi123_1, on 17 July 2019 - 12:54 PM, said:

Ease up on the rep system sport; I suggest perusing the FAQ.

To clarify what I am saying - expecting people to hand hold you through absolute zero to some understanding, with an undefined level ground level info, is a little much. Videos inherently have an issue of cherry picking topics and missing the good mortar that binds the bricks. The way to get that end-to-end information is to either take a long class or buy a book on the topic and work through it. Structured learning is preferable than flailing around with disconnected videos.

I understand what you are saying. And I do respect that that is going to be the most solid way for me to become proficient at this. I am not some savant who can just look at something and understand it so diligent study with long hours will eventually be what I put into this. All I am saying is that I can't do that now, so my only option seems to be trouble shooting among those who know way more then myself. So where as one day I will be on a forum like this returning the favor helping guys out, right now I just want a way to figure out these errors or worse, when I get a runtime error that doesn't throw anything but it just doesn't work.

I do appreciate you clarifying though. Honestly I just thought you were busting my balls, but I respect what you are saying.
Was This Post Helpful? 0
  • +
  • -

#14 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15160
  • View blog
  • Posts: 60,694
  • Joined: 12-June 08

Re: Closing my visible JFrame without closing my main application window.

Posted 17 July 2019 - 01:06 PM

Past folks conversations would disagree. You certainly can do that now! So a chapter every few nights or a week. Get the concepts and do a few exercises.

I have yet to come across someone who finally went the structured book route and said "well that made things worse!".

It gives you a baseline to work from - and that is always a good thing.

/rant ha!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1