0

I have browsed StackOverflow and have tried many different things. I will give some links: How to set AUTO-SCROLLING of JTextArea in Java GUI?, as well as I have used the Oracle website: https://docs.oracle.com/javase/tutorial/uiswing/components/scrollpane.html. But none of them have helped me.

txtara = new JTextArea("");
panel = new JPanel();
txtfld = new JTextField(""); 

scrollBar = new JScrollPane(txtara,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollBar.setPreferredSize(new Dimension(10, 10));

txtfld.setPreferredSize(new Dimension(740, 20));
txtfld.setLocation(new Point (0, 510));
txtfld.setBackground(Color.BLACK);
txtfld.setForeground(Color.WHITE);

txtara.setPreferredSize(new Dimension(740, 510));
txtara.setBackground(Color.BLACK);
txtara.setForeground(Color.WHITE);
txtara.setEditable(false);

panel.setPreferredSize(new Dimension(750, 575));
panel.setForeground(Color.BLACK);
panel.setBackground(Color.BLACK);

panel.add(scrollBar);
panel.add(txtara);
panel.add(txtfld);

DefaultCaret caret = (DefaultCaret)txtara.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

scrollBar.setViewportView(txtara);
TT.
  • 15,774
  • 6
  • 47
  • 88
  • First, remove `panel.add(txtara);`, you are already adding a scrollpane which contains the `txtara`. – Arnaud Apr 12 '19 at 14:08
  • 1) See [Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?](http://stackoverflow.com/q/7229226/418556) (Yes.) The sizes of text fields & areas should be suggested in the constructor with the number of columns & rows. 2) For better help sooner, [edit] to add a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). – Andrew Thompson Jan 12 '20 at 01:05

0 Answers0