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!

Grow and shrink JLabel to the left?

843806Oct 24 2007 — edited Oct 24 2007
I'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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 21 2007
Added on Oct 24 2007
4 comments
122 views