Setting JFrame maximum size that pack() can not violate
How can I set maximum JFrame size that pack() method can not violate.
Namely, I have JFrame and named it frame and I don't want let some parts of it be hidden beyond screen bounds (I mean one part of frame is showed, while the other one is not and I have to move frame to see that part Instead of this move I want to use scrollers). I want to set its maximum possible size to this of screen bounds but frame.pack() does not "obey" to this one (seems that it has a bigger priority than this setMaximumSize and similar options).
Re: Setting JFrame maximum size that pack() can not violate
What type of behavior are you looking for because there might be other ways to do so, like adding components to your JFrame dynamically or going into full screen mode.
Re: Setting JFrame maximum size that pack() can not violate
-- Add all components that would normally reside in the JFrame's contentPane to a JPanel instead
-- Add the JPanel to a JScrollPane (Notre: don't just add it -- read the API and/or tutorial on JScrollPane)
-- Set a preferredSize forr the JScrollPane
-- Add the JScrollPane to the JFrame at BorderLayout.CENTER or simply set it as the contentPane.
db
Re: Setting JFrame maximum size that pack() can not violate
Darryl.Burke I understand your idea but I have finished my project (actually I believed that it is finished and now teacher want one of panels to be inside JScrollPane).
Shortly, When program runs frame with 3 combos is shown I also have global variable ViewPanel that represents south part of this frame (and initially is empty) When user selects combo item another panel function returning JPanel is called and that panel is added to ViewPanel which is then added to frame's south part. If users selects another combo item ViewPanel is cleaned and function reurning panel is called ...
Now, instead of adding this returned panel I can put it in JScrollPane and add that JScrollPane to JViewPanel and later call pack() option on but pack option ignores all Size settings and make things on its own hand???