tags:

views:

191

answers:

6

I have been trying to set up a Java form in NetBeans with 15 - 20 visual components (buttons, textfields, etc.) and I have been using the Free Design layout paradigm on the MAC.

According to what I've read, the Free Design layout gives me various alignment guides, but does not try to force my alignments to specific row and column delimiters. However, I'm finding that when I do this, the width of my form may arbitrarily change, or some of the components I've already placed will move around radically when I make even small adjustments to other component positions.

Is there some way to anchor all these components, once placed, or is there a better layout paradigm that gives me the freedom to place components where I wish to?

Thanks for any help on this.

A: 

Maybe it's time to look into other LayoutManagers, like GridBag or something else that will give you what you want. The built-in choice by NetBeans sounds like a poor one for your needs.

If you choose a null LayoutManager you'll get absolute positioning.

But along with it comes absolute responsibility: No help in repositioning any elements.

duffymo
A: 

I strongly, strongly recommend MigLayout (And getting away from GUI layout tools). Any time you think you are saving by using a GUI tool quickly evaporates the second you run into layout manager behavior. Real UI's are coded, not built with drag and drop.

I found that it took me about 3 hours of fiddling to get used to MigLayout - after that break in period, I found it to be incredibly intuitive and powerful.

Kevin Day
It is nothing short of amazing that Netbeans has such an inferior GUI designer. I have programmed using at least four other GUI designers (Delphi, RealBasic, VisualBasic, IPhone SDK) and have never seen behaviour remotely this bad. I know Java is supposed to be platform independent, but certainly it should be adaptable to the two major platforms out there.
John R Doner
I've used lots of layout GUIs over the years, and Matisse is honestly the best that I've ever used. None are perfect, but Matisse is the only one that manages resizing in an intelligent way, ime. I'd suggest you watch the tutorials, as some anchoring is definitely possible.It'd also help if you'd post screenshots (or videos) of the behaviour that you are seeing. I've also gotten good responses to bug reports in the netbeans issues database.
jsight
A: 

I've found Using GroupLayout directly works really well. It can be confusing at first because horizontal and vertical layout are done separately, but once you get used to it it's not that difficult. You can definitely get things to align, and stick together when resizing. It's far better then using nested panels, GridBags, and that kind of thing.

MigLayout might work too, but GroupLayout is included in the JDK.

Chad Okere
A: 

You may want to look at the absolute layout. It allows you to put the component exactly where you want it, without all the jumping around.

Milhous
That is about the worst advice there is when it comes to layouting components.
Bombe
That depends on what you are wanting from your GUI.
Milhous
A: 

GridBag Layout is my favorite, and specially in Matisse (Netbeans GUI). You have like a wizard to graphically manage all the properties.
Will take you few examples to get things perfect as you want, but when you do, you will never look back.

Take a look at Sun Tutorials GridBag Layout

medopal
+1  A: 

IMHO, Matisse works best when you know what you want before you start. It doesn't seem to do so well with iterative changes.

Here are a few rules I follow when using Matisse in freeform mode. They don't make it wonderful, just less painful:

  • Build top-to-bottom and left-to-right. Most jumping happens when you go back an try to insert something.
  • Build it in one pass.
  • When you make progress, save it. There are conditions where Matisse will drop its undo list. Don't count on Ctrl-Z to bail you out. I use a local mercurial repo to track my changes.
  • Keep it small. The more elements, the more likely it is to blow up. Build it out of smaller components. For example, if you have a date field with a button to open a calendar
    • make that a component.
    • Add the component to the palette,
    • use that in the larger component.
Devon_C_Miller