I have a JTextArea
in a JPanel
that I would like to use a JScrollPane
with. I am using GridBagLayout
. When I run it it seems the frame makes room for the JScrollPane
but it does not show up, any help would be appreciated. I have been trying to study the docs.oracle page and here Add JScrollPane to a JPanel but for some reason it refuses to show up.
final JTextArea test= new JTextArea(5,30);
test.setLineWrap(true);
test.setWrapStyleWord(true);
test.setEditable(false);
JScrollPane spane = new JScrollPane(test);
spane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
JFrame frame = new JFrame ();
frame.setSize(800, 250);
frame.setTitle("test1");
frame.setLocation(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.getContentPane().add(spane);
GridBagConstraints k = new GridBagConstraints();
k.gridx = 4;
k.gridy = 5;
a.setConstraints(spane,k);
container.add(spane);