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!

About JTextArea's Vertical Alignment

843805Nov 20 2006 — edited Nov 20 2006
I Use setMargin() to leave a space on the top of the textarea, but it seems to be not working. Is there any good policy to set Vertical alignment for JTextArea? just as what JLabel's setVerticalAlignment method do.

Another question, I find getWidth() and getHeight() return 0, and I don't know why...

Can any guys give me some help? many many thanks !
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;

public class TestTextArea extends JFrame {
    
    public JTextArea textArea;
    
    public TestTextArea() {
        super("Test Text Area Y-AXIS Alignment");
        init();
    }
    
    private void init() {
        textArea = new JTextArea("adfkladjfakldfjasdfjaldjfakdfa" 
                + "asdjfalkdfjalksdfjasld;kfja;sdlfja da fasfasdadfasdf"
                + "asdfjaoicvnmcvmcnvmcxvnwerwerwemrnwerwoieruqweiqpowe");
        
        textArea.setPreferredSize(new Dimension(300, 200));
        textArea.setBorder(new LineBorder(Color.BLACK));
        textArea.setMargin(new Insets(100, 0, 0, 0));
        
        getContentPane().setLayout(new FlowLayout());
        getContentPane().add(textArea);
        
//        System.out.println(textArea.getWidth());
//        System.out.println(textArea.getHeight());
    }
    
    public static void main(String[] args) {
        TestTextArea app = new TestTextArea();
        app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        app.setSize(600, 480);
        app.setVisible(true);
    }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 18 2006
Added on Nov 20 2006
2 comments
208 views