This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I restart a Java application?
i am working on a java program which takes in bunch of values from the user and returns an answer. i have a "clear" button which makes the application ready to for a new set of input. So what i want is that this button should close the frame currently being viewed(create a window closing event and so on) and then call the main() function to create a new instance of my application. How should i do it? I tried this but it closes everything and the new frame doesn't show up:
WindowEvent wev = new WindowEvent(this, WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);
main(newInstance);
and also what does Toolkit do? suggest some readings for that. Thank you.
as per my comments I don't think this is best practise, but it is possible.
This has already been answered here:
How can I restart a Java application?
I hope this helps,
Related
This question already has answers here:
Getting active window information in Java
(3 answers)
Closed 4 years ago.
I'm trying to get the state of a window on Windows. I have to check if the window of word is active or inactive. I don't find any answer to this problem in Google.
Does anyone knows how to do this or if this is possible at all?
Window activeWindow = javax.swing.FocusManager.getCurrentManager().getActiveWindow();
The code above returns always NULL.
Thank you for your answers.
Regards
Roman
Try to use frame.hasFocus() or frame.isFocusOwner()
https://docs.oracle.com/javase/7/docs/api/javax/swing/JFrame.html
This question already has answers here:
Disable JButton focus border
(5 answers)
Closed 4 years ago.
i'm new there. My first issue:
When i start my GUI java swing application in Window Builder, first object is always selected
and when i click anything (button or anything) it's show like it's clicked and i don't want it to show. What command for this?
You should use this:
button.setFocusPainted(false);
java, swing, awt, remove focus from all objects
This question already has answers here:
Best way to store data between program runs in java?
(11 answers)
How can I save the state of my program and then load it?
(2 answers)
Closed 5 years ago.
For example, if I had checked a JCheckBox when I opened the program, how would I make the it remember the status of the checkbox so that the next time I open up the JFrame, the box stays checked.
I would also like to extend this question to other swing components like radiobuttons, color chooser, etc.
Attempted solution: The only way I can think of it is possibly making a new file so that the program can update and read the status of it and adjust the swing components when opened. However, this is too inefficient. I read online something about cookies but I am not too sure.
This question already has answers here:
Disable JFrame when a new JFrame is opened
(2 answers)
Closed 10 years ago.
I was wondering if it was possible to disable all other action when a JFrame is opened in Java.
Just like this?
Is there easy code for this?
This has been asked many times and the answer is always the same: use a modal JDialog or JOptionPane (which is a version of a modal JDialog), not another JFrame.
For example, please check out mKorbel's answer here.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Why is there no isFocused() in GWT?
Hi guys is possible check if a specific object has focus ? My problem in my web app is determine which object has focus when i press tab button, for each focus i need to do a specific action. thx
This is already addressed here - Why is there no isFocused() in GWT?
Please use the stackvoverflow search!!!!