CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2011
    Posts
    2

    Need help with buttons...

    Do you know why a JButton would take over the whole frame no matter what you set the size too? Like whatever I set my frame to, the button with is only suppose to 100,50 is still the size of a 500,500 frame. I do have 3 different buttons going into the JPanel object.



    I have a hunch it has to do with how the JPanel is formatting these??? You have any input?

  2. #2
    Join Date
    Apr 2007
    Posts
    442

    Re: Need help with buttons...

    Laying out the components in a container is strictly married to the LayoutManager that is used. Frames contentpanes use BorderLayout by default, anything added to BorderLayout by calling single param add(Component component) is added to BorderLayout´s CENTER. If no other components are added, the single one will thus consume whole of the available space.

    Use a LayoutManager that fits your purpose, check up on BoxLayout and FlowLayout.
    Remember that you can use multiple LayoutManagers to construct wgat you want.
    Remember that you can use transparent, non focusable components as fillers.

    As a last resort, you can always override the getMaximumSize() and getMinimumSize() methods of a component. This you however should do, when there is ample reason to do so.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured