java - JFrame doesn't conform JPanel's setMinimunSize() -
i expect jpanel
's setminimumsize()
confine resizing of jframe
too, doesn't.
the following example code:
import java.awt.borderlayout; import java.awt.color; import java.awt.dimension; import javax.swing.jframe; import javax.swing.jpanel; import javax.swing.jsplitpane; public class autoresize{ public static void main(string[] args) { jpanel leftpanel = new jpanel(); jpanel rightpanel = new jpanel(); leftpanel.setbackground(color.red); rightpanel.setbackground(color.blue); leftpanel.setsize(500,400); rightpanel.setsize(500,400); dimension d = new dimension(450,300); leftpanel.setminimumsize(d); rightpanel.setminimumsize(d); jsplitpane split; split = new jsplitpane(jsplitpane.horizontal_split, leftpanel, rightpanel); split.setdividerlocation(400); jframe frame = new jframe(); frame.getcontentpane().setlayout(new borderlayout()); frame.getcontentpane().add(split, borderlayout.center); frame.setsize(1000, 800); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setvisible(true); } }
if resize jframe
small size produces this:
what want jframe
couldn't resized smaller region jpanel
s' minimum size. there anyway implement this?
all need adding frame.setminimumsize();
, feel dumb.
thanks @andrew thompson @madprogrammer , @user1803551
import java.awt.borderlayout; import java.awt.color; import java.awt.dimension; import java.awt.toolkit; import javax.swing.jframe; import javax.swing.jpanel; import javax.swing.jsplitpane; public class autoresize{ private final dimension screensize = toolkit.getdefaulttoolkit().getscreensize(); private final double w = screensize.getwidth(); private final double h = screensize.getheight(); private final dimension d = new dimension((int) w/3,(int) h/3); public void run() { jpanel leftpanel = new jpanel(); jpanel rightpanel = new jpanel(); leftpanel.setbackground(color.red); rightpanel.setbackground(color.blue); //leftpanel.setsize(500,400); //rightpanel.setsize(500,400); leftpanel.setminimumsize(d); rightpanel.setminimumsize(d); jsplitpane split; split = new jsplitpane(jsplitpane.horizontal_split, leftpanel, rightpanel); split.setdividerlocation(400); jframe frame = new jframe(); frame.getcontentpane().setlayout(new borderlayout()); frame.getcontentpane().add(split, borderlayout.center); frame.setsize((int) w,(int) h); //frame.pack(); frame.setminimumsize(new dimension((int) w/3*2,(int) h/3*2)); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setvisible(true); } public static void main(string[] args) { autoresize test = new autoresize(); test.run(); } }
Comments
Post a Comment