java - JTextArea disappears when add JScrollPane -
i amateur in java swing , can't head around following problem.
as add jscrollpane
jtextarea
, neither of components visible in gui.
i know shouldn't add text area when add scroll (i commented line out), 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 me when used borderlayout
, not layout use.
goal place several text area's in frame.
what do text area displayed scroll, say, absolutelayout
(null
)?
your frame uses null layout.
you add scroll pane frame, size of scroll pane (0, 0) there nothing paint.
don't use null layout.
insteasd use layout manager. layout manager manage size , location of each components don't have to. don't try reinvent wheel, layout managers created reason , there absolutely no reason attempt use null layout when using jscrollpane/jtextarea.
textarea.setbounds(213, 11, 186, 240);
by way code nothing when add text area (or component) scroll pane. scroll pane uses own layout manager , override values.
jtextarea textarea = new jtextarea();
don't use code create text area. instead use like:
jtextarea textarea = new jtextarea(5, 30);
now text area can determine own preferred size , information can used layout managers.
Comments
Post a Comment