Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide a panel in Java [closed]

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.

like image 945
benxgao Avatar asked Nov 29 '25 23:11

benxgao


1 Answers

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);
    }
});
like image 181
Gabriel Avatar answered Dec 01 '25 12:12

Gabriel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!