Can someone help me add a scroll bar, both vertical and horizontal, in the JTextArea?
textarea1 = new JTextArea();
textarea1.setBounds(17,183,208,100);
textarea1.setBackground(new Color(40,40,40));
textarea1.setForeground(new Color(225,228,0));
textarea1.setEnabled(true);
textarea1.setFont(new Font("sansserif",0,12));
textarea1.setText(chat1);
textarea1.setBorder(BorderFactory.createBevelBorder(1));
textarea1.setVisible(true);
Thanks :)
The following is how it could be achieved:
JTextArea ta = new JTextArea();
JScrollPane sp = new JScrollPane(ta); // JTextArea is placed in a JScrollPane.
Once the JTextArea is included in the JScrollPane, the JScrollPane should be added to where the text area should be. In the following example, the text area with the scroll bars is added to a JFrame:
JFrame f = new JFrame();
f.getContentPane().add(sp);