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);
}
}