我想知道如何制作滚动文字。就像可以从右侧滚动到左侧的文本一样。如何在Java GUI中动画文本?动画/滚动文字
动画/滚动文字
回答
也许不是OP的答案,但我看不到的原因,通过工具Swing Timer
很简单,(可能是半透明的容器),并把那里JLabel
,(更新到JLabel
可能是从Chars
Array
到避免调整容器大小),例如
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JWindow;
import javax.swing.Timer;
public class SlideTextSwing {
private JWindow window = new JWindow();
private JLabel label = new JLabel("Slide Text Swing, Slide Text Swing, ..........");
private JPanel windowContents = new JPanel();
public SlideTextSwing() {
windowContents.add(label);
window.add(windowContents);
window.pack();
window.setLocationRelativeTo(null);
final int desiredWidth = window.getWidth();
window.getContentPane().setLayout(null);
window.setSize(0, window.getHeight());
window.setVisible(true);
Timer timer = new Timer(20, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int newWidth = Math.min(window.getWidth() + 1, desiredWidth);
window.setSize(newWidth, window.getHeight());
windowContents.setLocation(newWidth - desiredWidth, 0);
if (newWidth >= desiredWidth) {
((Timer) e.getSource()).stop();
label.setForeground(Color.red);
mainKill();
}
}
});
timer.start();
}
public void mainKill() {
Timer timer = new Timer(500, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
timer.start();
}
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
SlideTextSwing windowTest = new SlideTextSwing();
}
});
}
}
显示了几个相关的方法[这里](http://stackoverflow.com/q/3617326/230513)。 – trashgod 2012-04-05 12:48:03
感谢您编辑我的问题。 – 2012-04-14 07:23:17
感谢您的语法,它是帮助我。但是,我想用GUI Java在JLabel中进行滚动。 – 2012-04-14 07:45:06
- 1. WPF文字滚动动画
- 2. 滚动控制的文字动画
- 3. 滚动动画
- 4. 动画JavaScript滚动
- 5. 动画UIScrollView滚动
- 6. 滚动型动画
- 7. 滚动到动画
- 8. 在滚动上激活字母动画
- 9. 滚动文字
- 10. 动画滚动div与溢出滚动
- 11. Jquery - IE滚动中的动画动画
- 12. 动画向右滚动向下滚动并向左滚动动画
- 13. 带滚动条的动画文本
- 14. 页面动画 - 滚动文本
- 15. 画布滚动
- 16. 滚动/滚动条锁定后滚动动画
- 17. WPF字幕文本动画在其他控件中滚动
- 18. JQuery滚动动画颜色
- 19. 使用动画滚动
- 20. 动画滚动的图像
- 21. 滚动触发动画
- 22. iOS动画滚动视图
- 23. jQuery滚动不是动画
- 24. JQuery:滚动动画问题
- 25. Angular 4 - 滚动动画
- 26. 滚动显示CSS动画
- 27. mCustomScrollbar禁用滚动动画
- 28. jQuery动画与滚动
- 29. 动画视频滚动
- 30. 滚动时UITableViewCell动画
AFAIK,Java不一定是设计用来制作文字动画的。你可以做的是将'AffineTransforms'应用到'Label',但我真的怀疑它看起来不错。也许有一些库支持这种东西。 – posdef 2012-04-05 12:14:23
http://www.java2s.com/Code/Java/Threads/Swingandthreadsscrolltext.htm – 2012-04-05 12:20:07
您想在JTextField中,JLabel中移动文本,还是移动文本框/标签,或在面板上移动文本?在最后一种情况下:graphics.drawString是你需要的。 – 2012-04-05 12:24:16