Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Force marquee to use width of screen

843806May 6 2009 — edited May 9 2009
I've finally gotten my marquee to work inside my class. However, the text only scrolls in the space of the length of the text. I have set the size of the JFrame, set the preferred, maximum and minimum size of the JLabel. I have added a border around the JLabel to make sure the size has been set correctly. The JLabel is the size of the frame, yet the text still only scroll within the length of the text. This is what it looks like roughly:
------------------------------------------------------------------------------------------
|                                                                                         |
| xt scrolls here and repeats. My te                                                      |
|                                                                                         |
------------------------------------------------------------------------------------------  
And here is my code:
public static void scrollMarquee() {
		
		private static JFrame mainFrame = new JFrame();
	private static String marqueeText = "This is my text.It should scroll continuously.";
	private static JLabel textOutput = new JLabel("This...is...sample...text...");
		
		Timer marquee      = new Timer( 200, 
			new ActionListener() {
				public void actionPerformed( ActionEvent e ) {
							
					char firstChar  = marqueeText.charAt( 0 );//save char(0) to firstChar
					marqueeText = marqueeText.substring( 1, marqueeText.length() ) + firstChar;//Save chars from (1) to end + firstChar to             marqueeText
					
					textOutput.setText( marqueeText );
					
				}
			} );
Border border = BorderFactory.createLineBorder(Color.black); 
		mainFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		mainFrame.setSize(1200,200);
		mainFrame.setVisible( true );
		mainFrame.setTitle( "Marquee v1.0" );
		textOutput.setPreferredSize(new Dimension(400,75));
		textOutput.setMaximumSize(new Dimension(400,75));
		textOutput.setMinimumSize(new Dimension(400,75));
		textOutput.s
		textOutput.setBorder(border);
			
		Container content  = mainFrame.getContentPane();
		content.setLayout( new BorderLayout() );
		content.add( textOutput );
				
		marquee.start();
		

	}
What can I do to get my text to scroll all the way across the screen? I thought about adding spaces, but that seems like a messy idea. Is there a cleaner way to do this?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 6 2009
Added on May 6 2009
11 comments
408 views