java - Cannot setSize JTextPane/JScrollPane -
i have jframe borderlayout , have jtextpane/jscrollpane @ north splitpane in center , jpanel 4 jbuttons on @ south. frame's size (500, 470). want jtextpane fill of window set preferredsize (500, 450) has no effect.
here picture happens: http://postimg.org/image/3wslmppx7/
and here code:
public void initgui() { configwindow = new jframe(); configwindow.settitle(node.getdispname()+ " [" + node.getip() + "] configuration"); configwindow.setsize(500, 470); configwindow.setlocation(topologymain.dim.width/2-configwindow.getsize().width/2, topologymain.dim.height/2-configwindow.getsize().height/2); configwindow.getcontentpane().setlayout(new borderlayout()); configpane = new jtextpane(); configpane.seteditable(true); configpane.setname("config"); configpane.setpreferredsize(new dimension(500, 450)); configpane.setbackground(color.black); configpane.setcursor(new cursor(cursor.text_cursor)); scrollpane = new jscrollpane(configpane); scrollpane.setpreferredsize(new dimension(500, 450)); configwindow.getcontentpane().add(scrollpane, borderlayout.north); buttonpanel = new jpanel(); buttonpanel.setlayout(new gridbaglayout()); //buttonpanel.setpreferredsize(new dimension(500, 20)); gbc.insets = new insets(5,5,5,5); read = new jbutton("read"); gbc.gridx = 0; gbc.gridy = 1; gbc.fill = gridbagconstraints.horizontal; buttonpanel.add(read, gbc); apply = new jbutton("apply"); gbc.gridx = 1; gbc.gridy = 1; gbc.fill = gridbagconstraints.horizontal; buttonpanel.add(apply, gbc); load = new jbutton("load"); gbc.gridx = 2; gbc.gridy = 1; gbc.fill = gridbagconstraints.horizontal; buttonpanel.add(load, gbc); save = new jbutton("save"); save.setenabled(false); gbc.gridx = 3; gbc.gridy = 1; gbc.fill = gridbagconstraints.horizontal; buttonpanel.add(save, gbc); configwindow.getcontentpane().add(buttonpanel, borderlayout.south); splitpane = new jsplitpane(jsplitpane.vertical_split, scrollpane, buttonpanel); splitpane.setenabled(true); configwindow.getcontentpane().add(splitpane, borderlayout.center); configwindow.setvisible(true); filechooser = new jfilechooser(); }
solution gabriel negut in comments:
use pack()
- call after have added window.
from the documentation:
public void pack()
causes window sized fit preferred size , layouts of subcomponents. resulting width , height of window automatically enlarged if either of dimensions less minimum size specified previous call setminimumsize method.
if window and/or owner not displayable yet, both of them made displayable before calculating preferred size. window validated after size being calculated.
Comments
Post a Comment