I am an amateur in Java Swing and can't get my head around the following problem.
As soon as I add JScrollPane
to the JTextArea
, neither of components is visible in the GUI.
I know that I shouldn't add text area when I add its scroll (I commented that line out), but it doesn't help.
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JTextArea textArea = new JTextArea();
textArea.setBounds(213, 11, 186, 240);
// NOT CALLING frame.getContentPane().add(textArea);
scroll = new JScrollPane(textArea);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
frame.getContentPane().add(scroll);
It worked for me only when I used BorderLayout
, but this is not the layout I would like to use.
My goal is to place several text area's in the frame.
What do I do to get text area displayed with scroll, say, with AbsoluteLayout
(null
)?