• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to create a ticker affect for text?

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a program where you click a button and it adds a character to a JTextField. You can keep clicking on the button and it will add random characters to it.

What I am trying to do is when a new character is inserted, I want it to be inserted from the left side not added on to the right. Here's an example

Say I have the following text in a JTextField:
a b c d

and I want to insert 'e'. By default 'e' will be added so it looks like this
a b c d e

I want it to look like this
e a b c d

where the text is inserted from the left hand side. I have tried setting the caretposition for that JTextField to zero each time a click event takes place, but that didn't work. Any help is appreciated.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
textField.setText(randomChar + textField.getText());
 
Bob Zoloman
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That works perfectly, thanks!
 
reply
    Bookmark Topic Watch Topic
  • New Topic