我正在使用FullScreen Panel开发应用程序,有时我需要在屏幕的右侧显示第二个Panel.
为了开发它,我创建了一个带有AbsoluteLayout(来自NetBeans)的jPanel,其中包含另外两个面板.我计算每个面板位置和相对于屏幕分辨率的大小.
基本上,我有两个"状态".在第一个中,jPanel1的宽度= 100%,jPanel 2的宽度= 0%(所以我没有显示这个面板).第二种状态,当jPanel1的宽度= 75%且jPanel2的宽度= 25%时.
要做这些过渡我只重新计算每个面板大小,它运作良好,但我希望用一个动画做到这一点.随着jPanel2"滑动"进入屏幕.
下图解释了它: 链接到图像
我尝试了一些选择,但我在每次尝试都失败了.基本上,"动画"正在发生,但屏幕最终只会刷新.在我的最后一次尝试中,我尝试使用swing计时器,我的代码是:
变量:
-dataPanel:Major Panel,包含AbsoluteLayout并包含jPanel1和jPanel2
-visCons:当我在动画中更新witdh时,jPanel1位置的AbsoluteConstraints
-listCons:当我更新动画中的位置时,jPanel2位置的AbsoluteConstraints.
public static void showListPanel() {
timer = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int width = gd.getDisplayMode().getWidth();
int height = gd.getDisplayMode().getHeight();
int endVis = width - (width/4 + 20);
for (int i = width; i >= endVis; i--) {
visCons.width = endVis;
listCons.x = endVis;
dataPanel.repaint();
dataPanel.revalidate();
try {
TimeUnit.MICROSECONDS.sleep(10);
} catch (InterruptedException …Run Code Online (Sandbox Code Playgroud)