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 3 of 3

Thread: Jpanel preffered size exceed the nactual screen size

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Jpanel preffered size exceed the nactual screen size

    Hi, I am new to swing,
    MyClass is extends Jpanel, and MyClass having to instance of Jpanel, I am not having acces to MyClass Jpanel object, I am having instance of MyClass, and I dont want to create frame,


    Preffered size of MyClass instance is excedded then actual size, How can i resolve this.

    GridBagConstraint is used for MyClass jpanels objects


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: Jpanel preffered size exceed the nactual screen size

    Quote Originally Posted by manish.ctae@gmail.com View Post
    Preffered size of MyClass instance is excedded then actual size, How can i resolve this. ...
    This statement is very unclear to me. If you don't get a decent answer, could you clarify your question by adding more details of your problem?

    One way to change the preferredSize of a JComponent-extended class is to override the getPreferredSize() method, something like:

    public MyJPanel extends JPanel {
      private static final int PREF_WIDTH = 600;
      private static final int PREF_HEIGHT = 400;
     
      @Override
      public Dimension getPreferredSize() {
        return new Dimension(PREF_WIDTH, PREF_HEIGHT); 
      }
     
    }

  3. #3
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Jpanel preffered size exceed the nactual screen size

    Preffered size of MyClass instance is excedded then actual size, How can i resolve this.
    In addition to curmudgeon's post, you can also set minimum and maximum sizes for the component. Consult your favorite search engine for details..

Similar Threads

  1. How to get screen size in Applet
    By anm_brr in forum Java Applets
    Replies: 2
    Last Post: August 10th, 2011, 09:21 PM
  2. [SOLVED] can't get Image size.
    By samanesh in forum What's Wrong With My Code?
    Replies: 12
    Last Post: March 8th, 2011, 11:05 AM
  3. Adjusting Size of JPanel to Boundaries of Painting
    By aussiemcgr in forum Java Theory & Questions
    Replies: 6
    Last Post: November 22nd, 2010, 12:17 PM
  4. Limit File Size or Request Size
    By tarek.mostafa in forum Java Servlet
    Replies: 3
    Last Post: June 12th, 2010, 04:28 PM
  5. 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