Search code examples
javaswingnetbeansjtextarea

How can I make jtextarea resizable?


I did 2 jtextarea in one panel. When I click a button which makes invisible first jtextarea the other jtextarea shift up but its size does not change. But I want it shift up and change its size.(its height will be more) . I use setPreferredSize(new Dimension(x,y)); or I Use unresizable margin. How can I do that? Thanks.


Solution

  • Use setRows method and call revalidate on the panel.

    For example,

    Before hiding textarea1,

    textarea1.setRows(2);
    textarea2.setRows(3);
    

    After hiding textarea1,

    panel.removeAll();
    textarea2.setRows(5);
    panel.add(textarea2); 
    panel.revalidate();