I have a JTextArea
that I would want the user to input address of a person. I know that valid address that the user will enter will not exceed 5 rows
and 10 columns
. So I have set it to JTextArea (5,10)
. This way it works fine.
The problem is that when a user keeps on pressing enter
more that 5 times, the text area will begin to resize. I do not want to put the text area in a JScrollPane
since the text that the user will enter is not much for scrolling.
Question: How do we disable JTextArea
from resizing when a user press enter
?
Here is my code:
public class JTextAreaDemo {
private JFrame frame;
JTextAreaDemo(){
frame= new JFrame();
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new net.miginfocom.swing.MigLayout());
frame.setVisible(true);
frame.setLocationRelativeTo(null);
JLabel label=new JLabel("Address :");
JTextArea address= new JTextArea(5,20);
frame.add(label,"cell 0 0");
frame.add(address, "cell 1 0");
}
public static void main(String [] args){
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run() {
new JTextAreaDemo();
}});
}
}