swing - Java BoxLayout + JTextArea Wrapping -
i've got little notifications jpanel: thought beingness can scroll through notifications, each notification has own white box.
the greenish border jpanel wrapped in jscrollpane, orange border boxes jtextareas wrapped in jscrollpanes. i'm trying loop through code below , create each box right size, boxes expanding in image horizontal glue (i'm using boxlayout on jpanel (green box)).
the code:
for (int = 1; <= notifications.size(); i++) { arraylist s = notifications.get(i); // gets text info dashboard.notificationsarea.add(new jscrollpane(new jtextarea((s.get(1).tostring() + "\n" + s.get(0).tostring())))); // creates white boxes dashboard.notificationsarea.add(box.createverticalstrut(5)); s.clear(); } dashboard.notificationsarea.add(box.createverticalglue()); // adds glue fill space (not working?) (int ii = 0; ii < dashboard.notificationsarea.getcomponents().length; ii++) { if (dashboard.notificationsarea.getcomponent(ii) instanceof jscrollpane) { // style white box ((jscrollpane)dashboard.notificationsarea.getcomponent(ii)).setborder(borderfactory.creatematteborder(1, 1, 1, 1, settings.site_orange)); ((jtextarea) ((jscrollpane)dashboard.notificationsarea.getcomponent(ii)).getviewport().getview()).setlinewrap(true); ((jtextarea) ((jscrollpane)dashboard.notificationsarea.getcomponent(ii)).getviewport().getview()).seteditable(false); ((jtextarea) ((jscrollpane)dashboard.notificationsarea.getcomponent(ii)).getviewport().getview()).setwrapstyleword(true); } } dashboard.notificationsarea.revalidate(); }
how can create white boxes snap right size?
as shown in finish example, can override getpreferredsize()
enforce specific size nested scroll pane(s). may able farther refine preferred size shown @camickr in textpaneperfectsize
.
java swing
No comments:
Post a Comment