Results 1 to 6 of 6
  1. #1
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    64
    Rep Power
    0

    Default Button Location On Application Window

    I am creating an Application Window by New --> Windowbuilder --> Swing Designer --> Application Window, now when I add buttons to this layout (the default layout, I added no tools or features on top of the default), I have the options to add buttons to
    Java Code:
    BorderLayout.NORTH
    BorderLayout.EAST
    BorderLayout.SOUTH
    BorderLayout.WEST
    Which makes my Application layout look a little funny. For example, take into account this screenshot where I am only going to have 2 buttons on the Application. I would like to shrink the size of the Application and have the buttons side by side (and actually look more like buttons, not long skinny buttons, but more square-ish). What objects should I add, or settings should I change in order to be able to make the Application Layout look like what I am after?

    Screenshot:
    Button Location On Application Window-capture.png

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Button Location On Application Window

    There is also BorderLayout.CENTER, by the way. The general rule is that you need to combine layout managers for different effects. You can for example stick a JPanel component in "EAST" and "WEST" and then add your button to the JPanel, which by default has a FlowLayout but you can change it to get different spacing, sizing and ordering behavior. Take a look at the Swing tutorial on layout managers to get a feel for what each one does:

    https://docs.oracle.com/javase/tutor...ut/visual.html

    A warning: try not to fall for the seemingly awesome flexibility of the GridBagLayout. It will stab you in the back, eventually.

    And some advice: create the user interface with code, the Swing tutorial has all the information you need. Its easier than you think and you'll have full power over what goes where rather than having to fight with a designer tool that has its own mind and produces horrible to read code.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Button Location On Application Window

    I haven't done a GUI in a while but you may want to chose a different layout manager. Some managers are better for laying out individual components
    within a panel while others are better at laying out panels of components. You may want to check out the tutorials in my signature. They provide a good overview with examples of the various layout managers.

    Regards,
    Jim
    Last edited by jim829; 07-22-2016 at 04:24 PM. Reason: Too slow again...
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    64
    Rep Power
    0

    Default Re: Button Location On Application Window

    Quote Originally Posted by gimbal2 View Post
    And some advice: create the user interface with code, the Swing tutorial has all the information you need. Its easier than you think and you'll have full power over what goes where rather than having to fight with a designer tool that
    has its own mind and produces horrible to read code.
    Thanks, I will do! I like to have the "design" mode option just so I can see what my output will look like as I am building, w/o having to run as --> Java Application.

  5. #5
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    64
    Rep Power
    0

    Default Re: Button Location On Application Window

    Quote Originally Posted by jim829 View Post
    I haven't done a GUI in a while but you may want to chose a different layout manager. Some managers are better for laying out individual components
    within a panel while others are better at laying out panels of components. You may want to check out the tutorials in my signature. They provide a good overview with examples of the various layout managers.

    Regards,
    Jim
    No Java GUI's in a while, what do you normally code with Java?

    Will work through links in your sig, thanks!

  6. #6
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    64
    Rep Power
    0

    Default Re: Button Location On Application Window

    I have narrowed it down to using one of the 3 below - do any of you more experienced java devs have pitfalls of using any of these that I should watch out for?
    Java Code:
    FlowLayout
    GridLayout
    SpringLayout

Similar Threads

  1. Closing secondary window from button in primary window
    By KoncentriK in forum New To Java
    Replies: 4
    Last Post: 02-26-2012, 01:24 AM
  2. Getting location of the java application
    By sgthale in forum New To Java
    Replies: 2
    Last Post: 09-08-2011, 01:49 PM
  3. hiding passed parameters using window.location.href = 'params' method
    By kulangotski in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 07-01-2011, 12:49 PM
  4. Replies: 0
    Last Post: 05-20-2011, 12:07 PM
  5. how to get the location of some button
    By mary in forum Java 2D
    Replies: 2
    Last Post: 08-05-2007, 04:02 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
  •