I am working on a simple little swinging app for a relative, but I'm having trouble implementing animations ...
Here is a description of my layout:
I have a main window (created by instantiating, packaging, and displaying a JFrame). I told the contents pane of the main window to use GridBagLayout as my layout. My grid is 2 grids wide and 3 grids high. In the first column, I have three JButtons (A, B and C), each of which occupies one row of vertical grid space and one column of horizontal grid space. In the second column, I have another JPanel that has a width of one column and three rows tall.
This second JPanel is also configured to use GridBagLayout as a layout. In this case, there are two columns and one row. The left column has one column wide, one row JPanel high with button 1 inside it. The right column consists of only one JButton (Button 2), which also has a width of one column and one row height.
Here is a screenshot of what I just described:

Now that you understand what a layout is, let me explain what I was trying to do:
I am trying to use the Universal Tween Engine to resize the Jpanel that contains button 1. However, in my attempts, I end up with:

, JPanel, Button 1, ! , 2 , , , 2 JPanel, Button 1!
, JPanel, Button 1, GridBagLayout. -, .
, ... , "" GridBagLayout, , Jpanel, 1? GridBagLayout.invalidatelayout() GridBaglayout, JFrame.getContentPane().invalidate() . .
:
ImageManager.java:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import aurelienribon.tweenaccessors.swing.*;
import aurelienribon.utils.swing.*;
import aurelienribon.tweenengine.*;
import aurelienribon.tweenengine.equations.*;
public class ImageManager
{
public static JFrame mainwindow;
public static TweenManager tweenManager;
public static void main(String[] args)
{
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
InitGUI();
InitTween();
}
});
}
private static void InitTween()
{
((Window)mainwindow).addWindowListener(new WindowAdapter() {
@Override public void windowOpened(WindowEvent e)
{
new DrawingCanvas()
{
@Override protected void update(int elapsedMillis)
{
tweenManager.update(elapsedMillis);
}
}.start();
}
});
}
private static void InitGUI()
{
mainwindow = new JFrame("Imaffect");
Container pane = mainwindow.getContentPane();
pane.setLayout(new GridBagLayout());
pane.add(new JButton("Button A"), new GridBagConstraints(0, 0, 1, 1, 0, 1, GridBagConstraints.PAGE_START, GridBagConstraints.VERTICAL, new Insets(0,0,0,0), 100, 0));
pane.add(new JButton("Button B"), new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.PAGE_START, GridBagConstraints.VERTICAL, new Insets(0,0,0,0), 100, 100));
pane.add(new JButton("Button C"), new GridBagConstraints(0, 2, 1, 1, 0, 0, GridBagConstraints.PAGE_START, GridBagConstraints.VERTICAL, new Insets(0,0,0,0), 100, 20));
pane.add(InitPreviewGUI(), new GridBagConstraints(1, 0, 1, 3, 1, 1, GridBagConstraints.PAGE_START, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0, 0));
mainwindow.pack();
mainwindow.setVisible(true);
}
private static JPanel InitPreviewGUI()
{
JPanel panel = new JPanel(new GridBagLayout());
panel.add(InitSettingsGUI(), new GridBagConstraints(0, 0, 1, 1, 0, 1, GridBagConstraints.PAGE_START, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0, 0));
panel.add(new JButton("Button 2"), new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.PAGE_START, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0, 0));
return panel;
}
private static JPanel InitSettingsGUI()
{
JPanel panel = new JPanel();
SetupSettingsTweens(panel);
SetupSettingsContent(panel);
return panel;
}
private static void SetupSettingsTweens(JPanel panel)
{
Tween.registerAccessor(Component.class, new ComponentAccessor());
tweenManager = new TweenManager();
Tween.to(panel, ComponentAccessor.WIDTH, 1000)
.target(200)
.ease(Cubic.INOUT)
.repeatYoyo(-1, 200)
.delay(500)
.start(tweenManager);
}
private static void SetupSettingsContent(JPanel panel)
{
panel.add(new JButton("Button 1"));
}
}
, :
, , Eclipse Juno runnable jar:
, , :
- .
- ( )
- , SwingUtilities.invokeAndWait update()
- update(), Container.setSize() JPanel, 1.
! Thankyou:)
P.S. , . , , .