简体   繁体   English

在单击按钮时显示或隐藏面板的一部分的摆动方法?

[英]Swing method to show or hide part of a panel on button click?

I'd like to be able to show and hide (and therefore grow and shrink the jpanel as appropriate) in my swing application. 我希望能够在我的swing应用程序中显示和隐藏(并因此适当地增大和缩小jpanel)。 I've seen something similar on websites that I imagine uses JS and JQuery. 我在网站上看到过类似的东西,我想象它使用JS和JQuery。

What I'm after is the ability to click a button (that might say 'Advanced options') that then 'slowly' grows the panel and reveals ( setVisible(true) ) components. 我需要的是单击按钮的功能(可能会说“高级选项”),然后“缓慢地”扩大面板并显示( setVisible(true) )组件。

Is this possible using Swing? 使用Swing可以做到吗? I've tried looking round the web, and SO but I only seem to get JQuery questions, or unhelpful Java posts. 我曾尝试在网络上浏览,所以我似乎只收到JQuery问题或无益的Java帖子。 This is the closest I've found. 是我找到的最接近的。

Use a Swing Timer to animate your slide. 使用Swing计时器为幻灯片制作动画。 For example, this link has code that places the components in a JLayeredPane and slides one component over the other, again using a Swing Timer: slide effect with JPanel . 例如,此链接的代码将组件放置在JLayeredPane中,并将一个组件滑动到另一个组件上,再次使用Swing Timer: 带有JPanel的slide效果

Another useful effect is to fade out from one JPanel to another. 另一个有用的效果是从一个JPanel淡出到另一个。 For an example of this that uses a Swing Timer as well as a CardLayout, please check out this answer . 有关使用Swing计时器和CardLayout的示例,请查看此答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM