Grow and shrink JLabel to the left?
843806Oct 24 2007 — edited Oct 24 2007I'm interested in putting a JLabel on the right hand side of the screen and having it resize (grow and shrink) on an on-going basis to the left. Any pointers on this? Here's some code that places a label on the upper right of the screen and then resizes the label. It grows off the right hand side of the screen...
-----
import javax.swing.*;
import java.awt.*;
public class GrowRight
{
public static void main (String args[]) throws InterruptedException
{
JLabel label = new JLabel ("this is a test...");
JFrame frame = new JFrame ("GrowRight");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout (new FlowLayout());
frame.getContentPane().add (label);
frame.setSize (label.getPreferredSize());
frame.pack();
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation (d.width - frame.getSize().width, 0);
frame.setVisible (true);
Thread.sleep (50000);
label.setText ("for the next sixty seconds, this station...");
frame.setSize (label.getPreferredSize());
frame.pack();
}
}
-----
Any help would be appreciated! Thanks.