0

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.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Naveen
  • 7,944
  • 12
  • 78
  • 165

1 Answers1

2

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

StanislavL
  • 56,971
  • 9
  • 68
  • 98
  • :Exactly what I wanted.But still waiting for the answer related to Tween Engine as it provides more options and effects. +1 – Naveen Nov 15 '13 at 09:34
  • But the problem is that I have to keep those buttons always,I suppose.What if I want to come to home page from another page. – Naveen Nov 15 '13 at 09:36
  • You can add one more card when you need and slide to the new one. – StanislavL Nov 15 '13 at 09:48
  • I found another similar approach here http://stackoverflow.com/questions/11283554/slide-effect-with-jpanel . Is using this approach expected to produce flickers if suppose I had complex Panel with images and other components. – Naveen Nov 15 '13 at 09:51