How can I keep the selected state of a JCheckBox after closing and reopening the JFrame containing the JCheckBox? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 2

How can I keep the selected state of a JCheckBox after closing and reopening the JFrame containing the JCheckBox?

In a Java Swing application, I have two JFrames, one MainFrame and a 2nd JFrame with a JCheckBox and an OK JButton. In the MainFrame there is an Edit JButton to open the 2nd JFrame. When the 2nd JFrame opens, I select the JCheckBox to true and click OK JButton to close (dispose) the 2nd JFrame. I need the JCheckBox to be selected when I reopen the 2nd JFrame. However, when I open the 2nd JFrame again using the Edit JButton (in the MainFrame) I found the JCheckBox is unchecked. When I select a JCheckBox and close the containing JFrame, I expect that JCheckBox to remain selected when reopening the containing JFrame. Please see my two codes to review this further. https://code.sololearn.com/cXzFEj1ENxQ2/?ref=app https://code.sololearn.com/cOC8aM37v0MY/?ref=app

1st May 2019, 11:28 AM
abraha Tekulu
abraha Tekulu - avatar
27 ответов
+ 4
abraha Tekulu I typically avoid Java development and Desktop UI Apps in general. Therefore, I've not worked with Swing components before this question. 😉
2nd May 2019, 3:40 PM
David Carroll
David Carroll - avatar
+ 4
abraha Tekulu We're all here to ask and answer questions, so please just go ahead and ask. And I'd recommend you to not ask for likes because that might cause an avalanche of downvotes https://www.sololearn.com/discuss/1316935/?ref=app
1st May 2019, 12:21 PM
Anna
Anna - avatar
+ 4
abraha Tekulu I see your code. I'm on the road at the moment and can't respond. Can I edit your question to help you further?
1st May 2019, 2:05 PM
David Carroll
David Carroll - avatar
+ 4
abraha Tekulu I've rephrased your question and included links to your two codes. If I get some time later today to review this, I'll post an answer. In the meantime, the restated version of this question might help get the attention of other Java Swing developers.
1st May 2019, 2:15 PM
David Carroll
David Carroll - avatar
+ 3
abraha Tekulu I am sorry. I am not familiar enough with awt/swing to help you.
1st May 2019, 12:49 PM
Denise Roßberg
Denise Roßberg - avatar
+ 3
abraha Tekulu Is it okay for me to rephrase your question so that more people who might be able to assist can see your question?
1st May 2019, 2:01 PM
David Carroll
David Carroll - avatar
+ 2
What is the question?
1st May 2019, 11:51 AM
Denise Roßberg
Denise Roßberg - avatar
+ 2
abraha Tekulu But if you don't ask this java question nobody can help you.
1st May 2019, 12:17 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
~ swim ~ solved great idea really. Thanks very much.if necessary I can post it the solution guys.
1st May 2019, 8:04 PM
abraha Tekulu
abraha Tekulu - avatar
+ 1
~ swim ~ your idea seems great, please you can you see my code I already posted it yesterday ,it is public it may help for better understanding.
1st May 2019, 1:15 PM
abraha Tekulu
abraha Tekulu - avatar
+ 1
As much as you knows java it is enough, I will try your idea if it works.
1st May 2019, 1:59 PM
abraha Tekulu
abraha Tekulu - avatar
+ 1
David Carroll can you see my code it is public They are name CheckMain(main frame) and CheckB4 (2nd frame) .
1st May 2019, 2:03 PM
abraha Tekulu
abraha Tekulu - avatar
+ 1
Yes, sure but you understand my question yes?
1st May 2019, 2:07 PM
abraha Tekulu
abraha Tekulu - avatar
+ 1
David Carroll bravo I see you rephrase the question ,in good clarity!
1st May 2019, 2:14 PM
abraha Tekulu
abraha Tekulu - avatar
+ 1
Wow thanks very much David Carroll I see it .
1st May 2019, 2:16 PM
abraha Tekulu
abraha Tekulu - avatar
+ 1
~ swim ~ thanks very much bro I will try it and I will write you response.
1st May 2019, 3:01 PM
abraha Tekulu
abraha Tekulu - avatar
+ 1
I will do it with combobox also this , I come back with another question, I have one question . Because I believe I will get great ideas from this community.
1st May 2019, 8:16 PM
abraha Tekulu
abraha Tekulu - avatar
0
Please any one willing to help me with java question??
1st May 2019, 11:31 AM
abraha Tekulu
abraha Tekulu - avatar
0
Java question
1st May 2019, 12:12 PM
abraha Tekulu
abraha Tekulu - avatar
0
Anna @Yeva I just ask question if you can I need your help?
1st May 2019, 12:24 PM
abraha Tekulu
abraha Tekulu - avatar