简体   繁体   中英

How to change the content Pane of a JFrame with a slide-in or fade-in effect

I have two JPanel a and b .By default a is set as ContentPane.Jpanel a has a button on it which when clicked changes contentPane to panel b .But I want it to panel 'b' to slideIn or fade-In smoothly instead of sudden change.

Here is the code (in case necessary)

class GUI extends JFrame implements ActionListener
{
    JPanel a,b;
    JButton button;
    GUI()
    {
        super("Sliding Layout");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);

        button=new JButton("Slide");
        button.addActionListener(this);

        a=new JPanel();
        a.setBackground(Color.RED);
        a.add(button);

        b=new JPanel();
        b.setBackground(Color.GREEN);
        b.add(new JLabel("New Content Pane"));
        setSize(800,400);
        setContentPane(a);
    }
    public void actionPerformed(ActionEvent e)
    {
        button.setText("Changed");
        //what should I do here to change the contentPane to panel 'b' with green color 
        //with either slide-in-from -right or fade-in effect?
    }
}

After searching I found that Universal Tween Engine and Sliding Layout are two possible options.But Sliding Layout is I suppose based on Changing the grid cells but I want to change entire contentPane.So Tween Engine is the option but I tried to understand about an hour but no success.

I have attached the jars to my project.Can anyone of you please provide a code snippet or exact tutorial. Thanks in advance.

You can use this http://java-sl.com/tip_slider.html approach. It's based on CardLayout extension.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM