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?