views:

611

answers:

9
+3  A: 

And what method do you use to make layouts in java. Just code it, or use an IDE like netbeans?

NetBeans for GUI developers is like a calculator for grade schoolers: you really shouldn't use it until you know how to do things without it, but then it will save you a lot of time.

(I'd love to answer your primary question, but the firewall I'm behind is blocking the picture.)

Michael Myers
A: 

I used to love Motif's XmForm for this sort of thing. In Java, I usually put Boxes inside of boxes. So I have a vertical box. First row of the box contains a JLabel for the Instruction. Second row contains something for the label/result stuff, possibly some sort of grid. Third row contains whatever that blacked out thing, Fourth row contains the JTable. Then I'd spend some time to try to figure out how to do the lable/result stuff. Then I'd probably end up saying "dammit", and doing it as a GridBagLayout.

Paul Tomblin
+1  A: 

For myself gui-builders for swing or swt never worked that well that's why i code layouts myself using layout managers. Your question doesn't mention which gui-system you are using but i assume you want to use swing. If that's the case I would recommend to use GridBagLayout for your layout. It is not that easy to use in the beginning but as soon as you know how it works you can do most layouts in the way you want it to be and i think it is also the layoutmanager of choice for the layout you want to do.

Christian
+2  A: 

Well considering how simple the layout is I would suggest you use a BorderLayout with NORTH set to the top section in a container and the JTable in the CENTER of the BorderLayout. For the Top it appears to be a simple BorderLayout again with NORTH as the Instruction: south as the black box (possibly in a container with a FlowLayout). The center of the top pane appears to be 2 Containers of GridLayouts with 2 rows and 2 columns, so put thos in another container with a GirdLayout.

So in pseudo:

Container(BorderLayout)
{
  @NORTH
    Container(BorderLayout)
    {
       @NORTH
         Label(Instruction);
       @CENTER
         Container(GridLayout(2,1))
         {
            Container(GirdLayout(2,2))
            {
              Label() TextField()
              Label() TextField() 
            }
            Container(GirdLayout(2,2))
            {
              Label() TextField()
              Label() TextField()
            }
         }
       @SOUTH
         Container(FlowLayout())
         {
           JButton() //shaded thing?
         }
    }
  @CENTER
    {
      JTable
    }
}
bmeck
+2  A: 

I build everything by hand. Like Christian, I've had bad experiences with GUI builders; they always either refused to configure a couple of components quite right, or they generated huge amounts of unnecessary code which made later maintenance impractical, or both.

I used to do build a lot of UIs using GridBagLayout, but for years, I've never seen an office-environment UI that couldn't be built with nested BorderLayouts, GridLayouts, and the occasional BoxLayout or FlowLayout. About 98% of the stuff I've seen is doable with nested BorderLayouts.

In your case, the layout organization will be as bmeck says. Speaking from memory, using CENTER for the JTable (remember to put it in a JScrollPane!) and NORTH for everything else ensures that if you resize your JFrame, the JTable will get all of the extra space, and that should be exactly what you want. For the top labels and fields, the nested GridLayouts should ensure that each "column" of labels and fields will take up equal horizontal space. (They'll get only enough vertical space to be completely visible, and no more, since the JTable is taking up everything else.)

Everything else is just a matter of adding borders and setting the GridLayout padding reasonably.

Paul Brinkley
+1  A: 

I've used GUI layout generating tools for super rapid development (maybe get the first 2 or 3 iterations of an interface out of the way). I've ultimately found that using a simple fixed layout (no layout manager) with these tools is the best approach. Once we are starting to hone in on a design, we switch to manual layout.

Whenever I've tried to use GUI generators to create code for layout managers, I've almost always been bitten eventually where the layout would just stop working and I spent more time debugging the impossible to read auto-generated code than if I'd done the layout by hand anyway. For what it's worth, when we are doing the early phase of layouts, we use the Jigloo plugin for Eclipse. It's very inexpensive, and does a good job.

I'm a big fan of MiGLayout. I've found that it is incredibly easy to use for simple layouts, and is capable of doing extremely complicated layouts. All without the need to resort to nested panels, etc... JGoodies Forms is also good, but harder to use.

Kevin Day
+1  A: 

I wrote an article a while back on layout managers:

http://developer.java.sun.com/developer/onlineTraining/GUI/AWTLayoutMgr

It describes how nesting (as bmeck above demonstrates) can be used very effectively for many UI designs.

Scott Stanchfield
+1  A: 

Try table layout. Works great.

https://tablelayout.dev.java.net/

jedierikb
+1  A: 

Use GroupLayout

:)

All the alignments are pretty easy to do

OscarRyz