Reputation: 8268
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.
Upvotes: 0
Views: 565
Reputation: 57381
You can use this http://java-sl.com/tip_slider.html approach. It's based on CardLayout
extension.
Upvotes: 2