Reputation: 89
The Scrollbar does not appear in the Frame and the TextArea is somehow not editable, please help, thanks :)
import javax.swing.*;
import java.awt.*;
public class Test extends JFrame{
Container c;
JTextArea jT;
JScrollPane scroll;
public Test(){
c = getContentPane();
c.setLayout(new GridLayout(1,1));
jT = new JTextArea();
scroll = new JScrollPane(); //creating JScrollPane
scroll.add(jT); // adding jT to scroll
c.add(scroll);
}
public static void main(String[] args){
Test fenster = new Test();
fenster.setLocationRelativeTo(null);
fenster.setTitle("Test");
fenster.setSize(200, 200);
fenster.setVisible(true);
fenster.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Upvotes: 0
Views: 39
Reputation: 6711
You need initialize the Scroll Pane with the component for which you need to display the scroll bars.
scroll = new JScrollPane(jT); //creating JScrollPane; Do this
// scroll.add(jT); // don't do this
Upvotes: 1