Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Setting JFrame maximum size that pack() can not violate

  1. #1
    Junior Member
    Join Date
    Aug 2010
    Posts
    23
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default 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).


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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.
    Last edited by copeg; September 2nd, 2010 at 06:00 PM.

  3. #3
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default 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

  4. #4
    Junior Member
    Join Date
    Aug 2010
    Posts
    23
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default 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???

Similar Threads

  1. Setting JFrame to be only selectable window
    By aussiemcgr in forum AWT / Java Swing
    Replies: 3
    Last Post: July 22nd, 2010, 12:43 PM
  2. Java equivalent of Python’s struct.pack?
    By thiruvadi.e in forum Java SE APIs
    Replies: 2
    Last Post: July 14th, 2010, 03:09 AM
  3. Limit File Size or Request Size
    By tarek.mostafa in forum Java Servlet
    Replies: 3
    Last Post: June 12th, 2010, 04:28 PM
  4. Limit File Size or Request Size
    By tarek.mostafa in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: June 11th, 2010, 07:21 AM
  5. Setting up, using DataSources
    By jasonm in forum JDBC & Databases
    Replies: 1
    Last Post: March 4th, 2010, 10:37 PM