Apologies to tereferekuku for this diversion.
> I have an example containing, amongst other things, the technique:
>
> http://www.jroller.com/page/tackline?entry=trivial_swing
An interesting read. You say "GridBag has it's faults, but it's the only
layout manager worth using."
Personally, I'd far rather use MigLayout.
Of the standard[1] Layout Managers, GridBagLayout is the most capable[2]
but I tend to use it as a last resort. Often, nesting the other layout
managers seems to yield acceptable results.
I'm sure you must have explained your preference before but I couldn't
find it - pointers?

Signature
RGB
[1] http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html
[2] GroupLayout and SpringLayout are designed for GUI builders so I
haven't tried them, I'm assuming they don't allow you to do things that
can't be done at all in GridBagLayout.
Tom Hawtin - 13 Jun 2007 00:46 GMT
> Of the standard[1] Layout Managers, GridBagLayout is the most capable[2]
> but I tend to use it as a last resort. Often, nesting the other layout
> managers seems to yield acceptable results.
Actually I use GridBagLayout as first resort. Any kind of Swing
programmer is going to know the peculiarities of GridBagLayout. If you
dive straight in with it, your layout code should be uniform.
> I'm sure you must have explained your preference before but I couldn't
> find it - pointers?
I wrote some entires on specific layout managers:
http://www.jroller.com/page/tackline?entry=cushioning_springlayout
http://www.jroller.com/page/tackline?entry=distinctly_grouplayout
http://www.jroller.com/page/tackline?entry=do_the_funky_formlayout
and about making GridBagLayout and SpringLayout easier to use:
http://www.jroller.com/page/tackline?entry=gridbag_and_spring_layout_helpers
> [2] GroupLayout and SpringLayout are designed for GUI builders so I
> haven't tried them, I'm assuming they don't allow you to do things
> that can't be done at all in GridBagLayout.
SpringLayout is low-level. If you look at the source to GroupLayout
you'll see that it uses (different) springs. The only GUI builder that I
have seen that uses SpringLayout is the "demo" in the Bean Developer Kit
(BDK), IIRC. It doesn't provide abstractions and is just absurd to use.
GroupLayout is a bit of a pain to use by code. I've toyed with the idea
of giving it a facade that allows use of coordinates like GridBagLayout
(but without the hideous API).
They both allow you to do things that you can't in GridBagLayout. For
GroupLayou, you don't necessarily need to know whether one grid line
will be to the left of right of another, so avoiding nested panels. You
can link the sizes of a set of columns, say. SpringLayout is very
flexible and indeed extensible. It's just impossible to use.
Tom Hawtin
tereferekuku - 13 Jun 2007 09:25 GMT
> Apologies to tereferekuku for this diversion.
>
[quoted text clipped - 13 lines]
> I'm sure you must have explained your preference before but I couldn't
> find it - pointers?
To be honest I have no idea what it has to do with my problem (and the
original topic)...
Arek
RedGrittyBrick - 13 Jun 2007 22:14 GMT
>> Apologies to tereferekuku for this diversion.
<diversion snipped>
> To be honest I have no idea what it has to do with my problem (and the
> original topic)...
It has nothing to do with your original problem, it was a diversion.
This sort of thing happens a lot in newsgroup discussions. Sometimes it
seems to divert attention away from the original problem. This was not
my intention but I recognised it might be an undesired consequence,
hence my apology to you in advance.
Tom has already addressed your original question, I hadn't anything
useful to add.
Have you seen
http://java.sun.com/developer/JDCTechTips/2001/tt1120.html
It discusses the main options for achieving what you want. Towards the
end it discusses using PlainDocument to constrain a JTextField to digits
in, er, realtime. (I like to also emit a beep() for non-digits).
In many cases a JSpinner with a SpinnerNumberModel makes a good
alternative for entering integers.