I want to make objects (like textfields and buttons) disappear and exchange them with different ones depending on what box you tick on the programs GUI. How do I make them appear or disappear without deleting them? Or do I have to make different jFrames for each (and how)? (I am programming with NetBeans IDE if that helps)
2 Answers
In the source of the jFrame, or where ever you want to hide your GUI elements, if the main class is (should be) extending from the jFrame class, you can use
remove
For example:
public MainFrame() {
initComponents();
this.remove(btCalculateNumber);
//button created with netbeans GUI
}
But I recommend reading How to use setVisible in JFrames?
There are many, many methods from throwing them off screen in the same method you things in html, but typically the best way to do it is with the 'frame'.setVisible(false); method. You can tie this for example to radio list, and have a case structure for what's visible. (so basically button 1, frame 1,2,3, visable: 4 not, or button 2, frame 1,2,3, not visable, 4 visable... ext) For different jframes Class => extends jframe {code}
Honestly there's alot of good tutorials out their for this already, and I'd reccomend looking a couple up. (and also, avoid the netbeans drag/drop GUI builder till you understand... if your using it currently).

- 88
- 1
- 11
-
"Honestly there's alot of good tutorials out their for this already" would you mind linking a few? – Sep 07 '16 at 11:12