Java GUI Layouts

前端 未结 5 1954
耶瑟儿~
耶瑟儿~ 2021-01-07 02:55

Could somebody tell me which java layout I need to use to achieve the layout below:

\"Correct

相关标签:
5条回答
  • 2021-01-07 03:11

    Use multiple nested layout managers

    The example looks like a top-level BorderLayout with scroll pane in the CENTER location, a row of buttons (using FlowLayout) in the NORTH location and a GridLayout for the text fields in the WEST location. The latter could be improved by using a GroupLayout, which allows rows and columns to be sized individually but is somewhat complex to use.

    There's a great tutorial on using layout managers (unfortunately it seems to have disappeared from Oracle's servers and the link points to a probably transient copy).

    0 讨论(0)
  • 2021-01-07 03:12

    As stated in the previous comment, I would use MigLayout in this project. As you can use split, span and wrap after each field or textbox in order to get the correct layout. You can also debug Miglayout and see where your layout its right or wrong.

    download the latest version of MigLayout here : http://www.migcalendar.com/miglayout/versions/

    if using eclipse,

    • save it in a folder called Lib in the project folder.
    • configure the project build path but adding the jar file to the classpath.
    • Then you should be able to set the layout to MigLayout.

    panel.setLayout(new MigLayout());

    or to debug the layout - panel.setLayout(new MigLayout("debug"));

    0 讨论(0)
  • 2021-01-07 03:13

    I would just use MigLayout for the high level page layout, and then dropdown to the simple layout managers for the . It's essentially a grid layout, but it's very easy to use. Miglayout cannot wrap items though, and this is apparently a design issue in Swing. WrapLayout is a layout manager that gives you that functionality, but it can have issues.

    http://tips4java.wordpress.com/2008/11/06/wrap-layout/

    Looking at the screen shot you've provided I've mocked up the way you would want to divide it up. You'd have 9 rows total (0-8) and 3 columns total (0-2). For stuff like the controls at the very top, you will "span" them across all three columns.

    For the text, you just put the text inside of it's individual box in row 1, column 1 for First Name, or row 2, column 1 for Last Name, etc.

    You do the same thing with the input boxes.

    In the picture below the blue are the columns and the orange are the rows.

    grid layout

    So to summarize;

    • Use Miglayout for your high level layout. It's like using a table in HTML.
    • Use other layout managers to layout the items inside of the grid boxes that Miglayout provides.
    0 讨论(0)
  • 2021-01-07 03:21

    The best choise is using Gridbag layout as you have a bit complex UI and GridBag layout provides all the support you needed to achive the exact UI.You will have to use a parent panel and then the child panels in it.Each panel you will have to add seperate GridBag layouts.You can add insets and necessary growing to achieve what you want.

    0 讨论(0)
  • 2021-01-07 03:30

    Been a while since I worked with Swing, but it looks like the architecture is something like this:

    enter image description here

    1. You have a panel in the bottom which is BorderLayout
    2. Inside that, you add a total of 4 new panels, NORTH, WEST, CENTER and EAST
    3. in BorderLayout.NORTH you add a panel which have FlowLayout.LEFT
    4. in BorderLayout.WEST you add a panel which have GroupLayout.YAXIS. this panel contains the labels for names etc and the ENTER button
    5. in BorderLayout.CENTER you add the textfields that corresponds with the labels
    6. in BorderLayout.EAST you add the JSCrollpane.

    This might give you an idea and you can play around with these different panels to achive what you want

    0 讨论(0)
提交回复
热议问题