I am a novice programmer in Java Swing. I am trying to make a JScrollPane
with the JTextarea
so that the text will scroll. But the scroll is not working. Please help me with this. I don't know what I am doing wrong. I am providing my code snippet here.
JTextArea ta = new JTextArea("Hello.\n \n \n \n \n There.", 5, 10);
ta.setBounds(250, 60, 120, 60);
JScrollPane jp = new JScrollPane(ta,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jp.setBounds(250, 60, 140, 80);
jp.setPreferredSize(new Dimension(150, 150));
//jp.setViewportView(ta);
ta.setLineWrap(true);
panel.add(ta);
panel.add(jp);