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?
You have just created a
JTextAreaand added it to aJScrollPane. However I cannot see any text being added to yourJTextArea. The scroll option activates only when you have something to scroll through.Also I would suggest that you change your
HorizontalScrollBarPolicyandVerticalScrollBarPolicyfrom beingJScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS&JScrollPane.VERTICAL_SCROLLBAR_ALWAYStoHORIZONTAL_SCROLLBAR_AS_NEEDEDandVERTICAL_SCROLLBAR_AS_NEEDEDrespectively.