Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Scrolling text in Java

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i want to create a java program for Scrolling text which is given by the user at runtime...
 
Saloon Keeper
Posts: 5802
146
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where (and how) is this text displayed that you want to scroll? Are you looking for a CLI or GUI program?
 
Arun Kumarkrishna
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hearbg attached the output screen... i want that text to be scrolled.. when we input the message at runtime..
IMG-20170706-WA0014.jpg
[Thumbnail for IMG-20170706-WA0014.jpg]
This is my input screen
IMG-20170706-WA0015.jpg
[Thumbnail for IMG-20170706-WA0015.jpg]
I had inserted my text mesaage
IMG-20170706-WA0016.jpg
[Thumbnail for IMG-20170706-WA0016.jpg]
I need to scroll this text continuesly... can u help me
 
Bartender
Posts: 3508
150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An easy way is to create a JLabel with the required text. Add it to a JPanel with a null layout. Set a Timer, and when that timer fires, get the labels Rectangle with label.getBounds, adjust the left upper coördinates and invoke label.setBounds(rectangle). No repaint of the panel is needed.

You need to inspect the API for the getBounds and setBounds methods, and you may encounter some difficulties when you try to determine the size of the label. It really is simpler than it sounds.

Another easy way is to override the paintComponent of the panel with the scrolling text. Every time the timer fires, repaint the panel and redraw the text with g.drawString (...), using the updated coordinates (see the API of the Graphics class).
 
Rancher
Posts: 3072
24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the Marquee Panel which supports horizontal scrolling of text.
 
Arun Kumarkrishna
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Arun Kumarkrishna
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Arun Kumarkrishna
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These are the two coding parts i have used. can you correct it    
 
Tim Moores
Saloon Keeper
Posts: 5802
146
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, people here won't do your work for you, but we'll help you do it yourself.

So: what do those codes do now, and what do you want them to do instead? At which point does the actual behavior start to deviate from the desired behavior?
 
Piet Souris
Bartender
Posts: 3508
150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Arun

the code that you showed us is almost completely generated by the GUI builder of your IDE. Can you tell us how you rate your knowledge of Java Swing? Know anything about timers or how to add  panel to a panel?
 
Die Fledermaus does not fear such a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!