Results 1 to 5 of 5
  1. #1
    kyasuleyman is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Label preferred size problem

    I am trying to set the width and height of my image (which is actually just a label with an icon) as the same as the width and height of my screen so that it can cover the entire frame.

    My code is:

    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension dim = toolkit.getScreenSize();
    menubkg.setPreferredSize(new Dimension(dim.width, dim.height));
    Unfortunately this doesn't actually seem to affect the width and height values of my label in the free design layout, and i need to use this layout so that i may place other images in the frame without being too restricted. I have tried placing this in the customized code section of my label, to no avail, aswell as the componentshow event.

    Any suggestions on what i might do/what i might be doing wrong?
    Last edited by kyasuleyman; 05-01-2012 at 02:59 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Label preferred size problem

    Use code tags, not quote tags for posting code.
    Guide For New Members
    BB Code List - Java Programming Forum

    Quote Originally Posted by kyasuleyman View Post
    ... in the free design layout, and i need to use this layout so that i may place other images in the frame ...
    Any suggestions on what i might do/what i might be doing wrong?
    Using a visual designer that autogenerates code beyond your level of comprehension. A visual designer isn't a beginners' tool.

    Learn to hand code your GUIs. Trust me, it's easier, and also more satisfying as you get to control the layout. Go through Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Label preferred size problem

    Moved from New to Java.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    kyasuleyman is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Re: Label preferred size problem

    Quote Originally Posted by DarrylBurke View Post
    Moved from New to Java.

    db
    I appreciate the heads up but i really need more guidance on the issue directly at hand.

    What steps in regards to this problem do you recommend i take in order to overcome this issue with preferred size and layout?

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Label preferred size problem

    Also at www.javaprogrammingforums.com

    Please be forthright when cross posting to other sites. It's reasonable for everyone who participates in a discussion to be able to know what else is being said. But be aware that many won't spend time answering a question that may have been answered elsewhere.

    It's probably not what you want to hear (and I don't say it with any glee), but I agree with Darryl. The issue directly at hand is your inability to use some graphical gui designer or other with a "free design layout". Understanding what is involved in Swing layout is precisely the key to being able to use such tools.

Similar Threads

  1. Putting Label Inside Rectangle Problem
    By AryanArs in forum New To Java
    Replies: 3
    Last Post: 03-01-2012, 05:07 AM
  2. Replies: 5
    Last Post: 12-11-2011, 06:42 PM
  3. Preferred method for saving/accessing text files
    By joeyvitoro in forum New To Java
    Replies: 5
    Last Post: 12-05-2011, 07:32 PM
  4. Preferred way to code
    By mig in forum AWT / Swing
    Replies: 8
    Last Post: 12-20-2010, 06:12 PM
  5. Replies: 7
    Last Post: 12-03-2010, 04:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •