java - JTextArea not editable -
i came across following problem. want have scrollable jtextarea , create 1 that:
jscrollpane scrollabletextarea = new jscrollpane(); jtextarea text = new jtextarea(); scrollabletextarea.add(text);
the result have grey field cannot write into.
if create jtextarea works:
jscrollpane scrollabletextarea = new jscrollpane(new jtextarea());
where mistake leads behaviour?
if create jtextarea works:
a jscrollpane uses own custom layout manager. scrollpane contains areas for:
- horizontal/vertical scrollbars
- a "row header" , "column header"
- components @ top/right , top/left of scroll pane
- the "viewport" used contain component want scroll
when use following:
scrollabletextarea.add(text);
this mess scroll pane because component added scroll pane directly , not viewport of scroll pane
when use:
jscrollpane scrollabletextarea = new jscrollpane(new jtextarea(5, 20));
this create scroll pane , add text area viewport of scroll pane.
read section swing tutorial on how use scrollpanes more information on how scroll pane works.
Comments
Post a Comment