on-internet
← Community

A scrollable text area in Java

Stack Overflow ·

I am trying to display a scrollable text area in Java with a fixed size text area. I just could not it either occupies the whole frame or does not show. Much code is: public class newscroll { public static void main(String[] args) { JFrame frame = new JFrame("Simple JScrollPane Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(500, 500); JTextArea txt = new JTextArea(); frame.setLayout(new BorderLayout()); txt .setBounds(0,0,300,300); txt.setBackground(Color.green); for (int i = 1; i <= 50; i++) { txt.append(i +"\n"); } JScrollPane scrollPane = new JScrollPane(txt)

Comments

Sign in or sign up to comment and upvote.

No comments yet.