Reputation: 2285
Here is a code of a simple editor.
public class editor {
public static void main(String[] args) {
JFrame f = new JFrame();
final JTextArea area = new JTextArea(20,120);
JScrollPane scrollingResult = new JScrollPane(area,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
f.getContentPane().add(scrollingResult);
...
}
}
This doesn't work. JTextArea
is fine, so is the Frame
, but JScrollPane
is still disabled. Why could that be?
Upvotes: 3
Views: 499
Reputation: 6783
You have just created a JTextArea
and added it to a JScrollPane
. However I cannot see any text being added to your JTextArea
. The scroll option activates only when you have something to scroll through.
Also I would suggest that you change your HorizontalScrollBarPolicy
and VerticalScrollBarPolicy
from being JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS
& JScrollPane.VERTICAL_SCROLLBAR_ALWAYS
to HORIZONTAL_SCROLLBAR_AS_NEEDED
and VERTICAL_SCROLLBAR_AS_NEEDED
respectively.
Upvotes: 5