I am working on a java questionnaire app, and there is one problem: for example, there is two main questions, and the first main question has a subquestion, all the questions are sigle choice. Assuming that I click on one choice of the first main question, its subquestion should be triggered out and displayed between the first main question and the second question. If I click on the choice again, the subquestion should be disappeared. How can I make the question panels show and hide animately? Can you just tell me the basic methods? Thank you.
Asked
Active
Viewed 1.1k times
3
-
1possible duplicate of [Java Swing: How to change GUI dynamically](http://stackoverflow.com/questions/5750068/java-swing-how-to-change-gui-dynamically) – trashgod Oct 26 '11 at 01:47
-
See also this [Q&A](http://stackoverflow.com/questions/5812002/removeall-not-removing-at-next-validate). – trashgod Oct 26 '11 at 01:49
-
Just swap JPanels using a CardLayout. That's the "basic methods". – Hovercraft Full Of Eels Oct 26 '11 at 02:55
1 Answers
3
Here is some basic code on an example of hiding something visually in java.
public static void main(String args[]){
JFrame f = new JFrame();
f.setLayout(new BorderLayout());
final JPanel p = new JPanel();
p.add(new JLabel("A Panel"));
f.add(p, BorderLayout.CENTER);
//create a button which will hide the panel when clicked.
JButton b = new JButton("HIDE");
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
p.setVisible(false);
}
});