java - Writing at the bottom of JTextArea -


i have jscrollpane , jtextarea (editable) 10 rows. want first user input appear @ bottom of jtextarea , recent input should push previous input upward. achieve use textarea.setmargin(new insets(x,0,0,0)); , works should - except second input toggle jscrollpane.

how can start @ bottom of jtextarea , enable scrolling when entire original viewport filled?

enter image description here

basically, add jtexttext onto jpanel jpanel acts filler, causing jtextarea occupy smallest space needs.

i did using gridbaglayout force fill occupy of space could...

scrolling

import java.awt.borderlayout; import java.awt.color; import java.awt.eventqueue; import java.awt.gridbagconstraints; import java.awt.gridbaglayout; import javax.swing.jframe; import javax.swing.jpanel; import javax.swing.jscrollpane; import javax.swing.jtextarea; import javax.swing.uimanager; import javax.swing.unsupportedlookandfeelexception;  public class testtextarea {      public static void main(string[] args) {         new testtextarea();     }      public testtextarea() {         eventqueue.invokelater(new runnable() {             @override             public void run() {                 try {                     uimanager.setlookandfeel(uimanager.getsystemlookandfeelclassname());                 } catch (classnotfoundexception | instantiationexception | illegalaccessexception | unsupportedlookandfeelexception ex) {                 }                  jframe frame = new jframe("testing");                 frame.setdefaultcloseoperation(jframe.exit_on_close);                 frame.setlayout(new borderlayout());                 frame.add(new jscrollpane(new testpane()));                 frame.pack();                 frame.setlocationrelativeto(null);                 frame.setvisible(true);             }         });     }      public class testpane extends jpanel {          private jtextarea ta;          public testpane() {             setlayout(new gridbaglayout());             gridbagconstraints gbc = new gridbagconstraints();             gbc.gridx = 0;             gbc.gridy = 0;             gbc.weightx = 1;             gbc.weighty = 1;             gbc.fill = gridbagconstraints.both;              jpanel filler = new jpanel();             filler.setbackground(color.white);             add(filler, gbc);              gbc.gridy = 1;             gbc.weighty = 0;             ta = new jtextarea(1, 20);             add(ta, gbc);         }     }  } 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -