在Java上的JForm中滑动JPanel内容 [英] Slide JPanel Content in a JForm on Java

查看:185
本文介绍了在Java上的JForm中滑动JPanel内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题。我想制作一个摇摆形式,当点击一个按钮时,他将一个面板(带有他的内容)向左滑动,这样右边的面板就会取代它,效果很流畅。

I have a question. I want to make a swing form that, when clicking in a button he slides a panel (with his content) to the left so the panel on the right replaces it with a smooth effect.

我试过一段时间来检查面板的大小,然后将其最小化并显示下一个这样的:

I Have tried to do a while how checks the size of the panel and then minimize it and shows the next one like this :

    while (jpanelprincipal1.getWidth() < 439 || jpanelprincipal1.getHeight() > 250)
    {
        int panel1width = jpanelprincipal1.getWidth();
        int panel2height = jpanelprincipal1.getHeight();
        jpanelprincipal1.setSize(panel1width -- , panel2height --);
        jpanelprincipal2.setSize(440,250);
    }

我在C#中使用了这个技巧但是使用了Application.DoEvent(); (显然它在java上不可用)。

I used this trick in C# but with the Application.DoEvent(); (how obviously it's not available on java).

无论如何我可以制作2个或更多面板的幻灯片效果吗?

Is there anyway i can make a slide effect of 2 or more panels?

顺便说一句:对不起,我的英语非常糟糕!

BTW : Sorry for my very bad english !

先谢谢,
Luis Da Costa

Thanks In Advance, Luis Da Costa

推荐答案


他将一个面板(带有他的内容)向左滑动,所以右边的面板用平滑的效果替换它

he slides a panel (with his content) to the left so the panel on the right replaces it with a smooth effect

您提到的问题是您希望面板滑动,但代码看起来像是在尝试让面板缩小,所以它由另一个面板替换。

You question mentions you want the panel to "slide", but the code looks like you are trying to get the panel to "shrink", so it is replaced by another panel.

假设您有两个面板,每个面板具有相同的尺寸,那么您可以滑动一个面板,而另一个面板滑入视图。

Assuming you have two panels each with the same size, then you can "slide" one out of view while the other slides into view.

为此,您可以使用带有GridLayout的面板。这样每个组件的大小都相同。然后将面板添加到滚动窗格中,而不使用任何滚动条。滚动窗格的大小需要设置为第一个compnoent的大小。然后,您可以通过更改视口的位置来滑动两个面板。所以在你的Timer中你会有类似的代码:

To do this you an use a panel with a GridLayout. This way each component will be the same size. Then you add the panel to a scrollpane without any scrollbars. The size of the scrollpane will need to be set to the size of the first compnoent. Then you can "slide" the two panels by changing the position of the viewport. So in your Timer you would have code something like:

JViewport viewport = scrollPane.getViewport();
Point position = viewport.getViewPosition();
position.x += 5;
viewport.setViewPosition( position );

当位置大于组件大小时,您将停止计时器。

You would then stop the Timer when the position is greater than the size of the component.

这篇关于在Java上的JForm中滑动JPanel内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆