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: How do I prevent buttons from flowing over when the window is dragged.

  1. #1
    Junior Member Spencer4908's Avatar
    Join Date
    Jul 2014
    Location
    UTAH, USA
    Posts
    12
    My Mood
    Cheerful
    Thanks
    1
    Thanked 1 Time in 1 Post

    Question How do I prevent buttons from flowing over when the window is dragged.

    I'm using a BorderLayout, with 26 buttons to make up the alphabet from a keyboard. All the spacing looks great, but when you drag the screen out, everything gets jumbled. I would prefer to have everything stretch out, and keep the same positioning, or everything move towards the center still keeping the keyboard style positioning of the buttons but increasing the size of the window. How should I approach this? Will a BorderLayout work for what I want, or should I try something else?

    Currently to keep the buttons spaced apart I am keeping there preferred size to 25, and using horizontal and vertical struts to get the buttons positioned like I want.

    This is how it is if I keep it the width and height 400, 400.
    ex1.jpg

    This is what happens when its stretched or shrunk.
    ex2.jpg


    This is an example of one of the ways I would prefer it
    ex4.jpg

    This is would also be acceptable.
    ex3.jpg

    I apologize if my question is confusing, and would be glad to clarify.
    Last edited by Spencer4908; July 24th, 2014 at 02:21 PM.


  2. #2
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    900
    Thanks
    0
    Thanked 166 Times in 148 Posts

    Default Re: How do I prevent buttons from flowing over when the window is dragged.

    How do you use a border layout for that? That does not make any sense to me whatsoever.

  3. #3
    Junior Member Spencer4908's Avatar
    Join Date
    Jul 2014
    Location
    UTAH, USA
    Posts
    12
    My Mood
    Cheerful
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: How do I prevent buttons from flowing over when the window is dragged.

    I used struts, and preferred sizes to force it to do that. However I decided to use the BoxLayout, because it does what I need it to do, I was able to fix the problem I was having. What I did to solve it was, I changed the frame to a BoxLayout Y-Axis, and added 3 panels that use the BoxLayout X-Axis, I then changed the size of the panels to push the buttons closer together, to make it look nicer. That seemed to do the trick, if I drag it out, it has the result of the bottom image of my original post.

    Anyway thanks for attempting to help.

Similar Threads

  1. Applet viewer window is diplaying in fron of the current window every time
    By jsreddy99 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 24th, 2013, 07:16 AM
  2. Replies: 2
    Last Post: August 27th, 2012, 10:19 PM
  3. Prevent object going outside of screen?
    By JakkyD in forum Java Theory & Questions
    Replies: 2
    Last Post: May 7th, 2012, 11:56 AM
  4. Replies: 1
    Last Post: December 17th, 2011, 03:32 AM
  5. Replies: 1
    Last Post: July 20th, 2011, 09:03 AM