Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Layout question

Reply
Thread Tools

Layout question

 
 
nukleus
Guest
Posts: n/a
 
      01-19-2007
In article < .com>, "Andrew
Thompson" <> wrote:
>nukleus wrote:
>> In article <. com>, "Andrew
>> Thompson" <> wrote:

>....
>> >The specific 'for instance' I am thinking of, is that
>> >I know of a comonent* that was designed in
>> >NetBeans (in the NetBeans *form* *editor*, which
>> >is the NB 'make a GUI' wizard), that itself actively
>> >generates GUI's based on XML descriptions
>> >(which were from a legacy source).

>>
>> I like that.
>> Where can i see it? Do you have a reference on it
>> by any chance?

>
>The entire SaverBeans project is open source, you
>can see the latest version of the SettingsDialog.java here..
><https://jdic.dev.java.net/source/bro...nsaver/src/api
>/org/jdesktop/jdic/screensaver/SettingsDialog.java?rev=1.5&view=auto&content-ty
>pe=text/vnd.viewcvs-markup>
>...and the NetBeans based SettingsDialog.form here..
><https://jdic.dev.java.net/source/bro...nsaver/src/api
>/org/jdesktop/jdic/screensaver/SettingsDialog.form?rev=1.3&view=markup>
>The XML files they use to describe the GUI, are detailed here..
><https://screensavers.dev.java.net/config/>
>
>HTH
>
>Andrew T.


Thanks a lot. Appreciated indeed. That helps quite a bit.
I looked at it and it looks exactly what i was interested in.
Great!
Hope i can build it without much hassle :--}
:--{

good luck.

 
Reply With Quote
 
 
 
 
nukleus
Guest
Posts: n/a
 
      01-20-2007
I am converting some frames based that used null layout
to use gridbag layout. The problem i encountered was this:
One of the frame uses a lot of text fields and labels with their
names. The best approach would be to use tabs, as all the
fields naturally want to be layed out vertically. But there are
so many of them, that the frame's Y size is way too big.

Since i started using gridbag for other frames, i'd look to keep
some consistency and use it in this case also. I though using
a scroll pane (sorry, but i have to use AWT code only).
So, i tried to use gridbag on the main frame. The main frame
includes the scrollPane, that has a panel, and a pannel has
all the field name labels and text fields themselves.
And all sort of hell broke loose on me.

I am not even sure how to size things so that the scroll bars
would even appear. Field name labels seem to be completely
gone to luch when you run this class. For some reason, the
field name labels have an extra few hundred pixels added
in X orientation in run time even though witdh padding is set
to 3 pix, ancor to west and fill to none. All the external insets
are 3 pix.

Can anyone tell me if the overall idea make sense and
how to size the frame in relationship to scroll pane and
a panel?

Is there any particlular sequence of calls that one has to
follow? What ARE those calls in order for it all to work properly.
I've spent several hours struggling with this thing, but it seems
to go nowhere. Initially, i was able to see the scroll bars but then
they were gone even though while creating a frame object
i explicitly asked for scroll bars always.

Thanks.

P.S. I just like to ask you not to tell me to download 50+ megs of
latest jdk from sun. It isn't possible in this situation. For one thing,
i am not even sure even if i downloaded it, i would be able to use
it on the first place because of ms jv++ 2003 and its limitations.
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      01-20-2007
nukleus wrote:
> I am converting some frames ...

(big snip)
> Can anyone tell me if the overall idea make sense and
> how to size the frame in relationship to scroll pane and
> a panel?


Don't know - long paragraphs of descriptive text
about computer programs, give me a head-ache -
so I skipped them.

But you might get my help if you can provide an
SSCCE* that crudely describes what you want,
but fails to do it.

* <http://www.physci.org/codes/sscce>

Note also that I do not recommend using GBL
for layouts in all frames simply for 'consistency'
and that GBL can cause some unusual problems
that are not normally seen in other layouts.

Have you heard of the concept of 'nested layouts'?

Andrew T.

 
Reply With Quote
 
nukleus
Guest
Posts: n/a
 
      01-21-2007
In article <. com>, "Andrew
Thompson" <> wrote:
>nukleus wrote:


>Note also that I do not recommend using GBL
>for layouts in all frames simply for 'consistency'
>and that GBL can cause some unusual problems
>that are not normally seen in other layouts.


Such as?

It seems to work fine here even with relatively complex
layouts that include all sorts of gui elements and i worked
out a way to completely separate the GUI layout related code
so that i could redesign layout without affecting the routines
that use that frame.

From what I understand, GBL, is probably
the closest thing to run time rendering work.
No matter what kind of layout you use, it will all inevitably
translate into calculations of pixel offsets for each gui
element. GBL seems to provide the most complete and
most detailed description of each element and you should
be able to lay out any gui you can imagine using it.

I wonder what kind of problems are you talking about.

>Have you heard of the concept of 'nested layouts'?


Nope. But if you tell me, I will.

>Andrew T.


Thanks to you, I am rewriting all the GUI code to use
layouts and it works fine so far.


 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      01-21-2007
nukleus wrote:
> In article <. com>, "Andrew
> Thompson" <> wrote:
> >nukleus wrote:

>
> >Note also that I do not recommend using GBL
> >for layouts in all frames simply for 'consistency'
> >and that GBL can cause some unusual problems
> >that are not normally seen in other layouts.

>
> Such as?


- Collapsing components with no min. size set.
- Focus and keyboard navigation.

> >Have you heard of the concept of 'nested layouts'?

>
> Nope. But if you tell me, I will.


I talk better in code, here is a (very) simple nested layout
that puts a GridLayout for the buttons in the NORTH
of a BorderLayout.
<http://www.physci.org/codes/layout/JThermostatLayoutFrame.java>
It could probably do with some padding in the
layout constructors, and maybe and EpmtyBorder
around the lot, but it shows the concept of putting
one layout, inside an area of another.

> ..I am rewriting all the GUI code to use
> layouts and it works fine so far.


I think you will find that is the most
stable and robust course of action.

Andrew T.

 
Reply With Quote
 
nukleus
Guest
Posts: n/a
 
      01-24-2007
In article <. com>, "Andrew
Thompson" <> wrote:
>nukleus wrote:
>> In article <. com>, "Andrew
>> Thompson" <> wrote:
>> >nukleus wrote:

>>
>> >Note also that I do not recommend using GBL
>> >for layouts in all frames simply for 'consistency'
>> >and that GBL can cause some unusual problems
>> >that are not normally seen in other layouts.

>>
>> Such as?

>
>- Collapsing components with no min. size set.


That's exactly what I am seeing in one of the frames.
Working on it right now and I don't particularly like
what I am seeing. I have a few checkboxes in two rows
and they just dissapear in run time.

>- Focus and keyboard navigation.


That is the problem for me. Tabbing should work
as expected. I kinda forgot about it and didn't test it
upto now. Thanks for reminding me.

>> >Have you heard of the concept of 'nested layouts'?


>> Nope. But if you tell me, I will.


>I talk better in code, here is a (very) simple nested layout
>that puts a GridLayout for the buttons in the NORTH
>of a BorderLayout.
><http://www.physci.org/codes/layout/JThermostatLayoutFrame.java>
>It could probably do with some padding in the
>layout constructors, and maybe and EpmtyBorder
>around the lot, but it shows the concept of putting
>one layout, inside an area of another.


Well, this is exactly what I am thinking about right now.
And i have already done some nested layout without
even realizing that it could be a good idea. It was all
done on intuition. But now, once you are talking about it,
I'll investigate this thing more carefully.

I have a couple of frames that have several option checkboxes
and they should be layed out at an equal X distance, which is
not quite straightforward with gridbags. So, i created panels
in the frame object that are meant to layout checkboxes
using a separate layout.

Some other text fields and labels want a different layout
and gridbag seems to be working fine for it as i can have
labels and comment words around the text entries. So,
i created another layout, which is also a gridbag.

And there are a few buttons that want to be layed out
with their own layout so they all look properly aligned.
So, there is another panel to layout those.

Not sure I am moving in a right direction though.

With gridbags, I noticed that with complex frames,
you won't be able to get away with a single layout object,
just like you say.

>> ..I am rewriting all the GUI code to use
>> layouts and it works fine so far.

>
>I think you will find that is the most
>stable and robust course of action.


Great. That is exactly what I want. Spending all this
time on GUI, I wouldn't want to even think about all
this in the future and have ANY kind of problems with it
once I am done.

Thanks again.

>Andrew T.
>

 
Reply With Quote
 
nukleus
Guest
Posts: n/a
 
      01-29-2007
Can anyone explain to me how nested gridbag layout works?
I have a frame with several buttons, checkboxes, text area,
and text fields. They all want to be layed out in their own
way.

I used a gridbag layout for the frame itself and created
panels for 3 different areas of the frame to manage different
kinds of items also using their own gridbags.

Buttons want to be layed out horizontally,
so I put them in their own panel with gridbag layout.

Text area and text fields want to be layed out vertically,
so I put them in their own panel, also gridbag layout.

Checkboxes want to be layed out at an equal distance
from each other horizontally, but there are more of them
that fit the frame horizontally, so there are a couple of
rows for those. Also put them in a gridbag layout.

Yes, I know it is an overkill to use gridbag layout
for all those categories, but i just don't know of
a better way of doing it.

To make the story short, this whole thing behaves
like crazy. In some cases buttons dissapear,
in other cases, text fields and textarea are of
a miniscule size and so on despite the fact that
fills are used to make sure they stretch full frame
size horizontally.

Questions:

1. What would be the right way of approaching this
frame's layout?

Would it be to use different kinds of layouts for each
panel, or is it reasonable to use a gridbag for all
of them?

2. What is a critical thing in gridbag in terms of
things simply dissapearing in run time, such as what
I am seeing with buttons and text fields and their
sizes?

3. Why do my text fields and text areas become
of miniscule size even though i have fill set
to .4 or so? How come they can possibly become smaller
than the font size in terms of Y size?

4. When i set constraints for each panel, using the
approximate relationships to the frame size in Y
dimension, such as .2, does it mean that my panel
will take 20 percent of Y size of the frame?

5. If that panel has buttons or text fields, how do i
set Y constraints on those fields? Are they expressed
in terms of their part of their panel, or is their
Y weight calculated using the frame's gridbag
constraints?

6. Is there any humanly readable reference on
gridbag layout or layout as such?

Thanks.

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      01-30-2007
On Jan 30, 6:50 am, nukl...@invalid.addr (nukleus) wrote:
....
> 1. What would be the right way of approaching this
> frame's layout?
>
> Would it be to use different kinds of layouts for each
> panel, or is it reasonable to use a gridbag for all
> of them?


No. GBL is not the best layout for any variety
of things for which other layouts were defined.
GBL is not some 'magic pill' that can handle
all layouts.

(And as an aside, I thought you had gone over to
using nested layouts, with GBL where appropriate.
It now seems you are veering back to GBL!)

I doubt you will get GBL working reliably for you
before learning how a slew of the other layouts
work, and once you do that, you'll find that you
use GBL much less often.

Andrew T.

 
Reply With Quote
 
nukleus
Guest
Posts: n/a
 
      01-30-2007
In article < .com>, "Andrew
Thompson" <> wrote:
>On Jan 30, 6:50 am, nukl...@invalid.addr (nukleus) wrote:
>....
>> 1. What would be the right way of approaching this
>> frame's layout?
>>
>> Would it be to use different kinds of layouts for each
>> panel, or is it reasonable to use a gridbag for all
>> of them?

>
>No. GBL is not the best layout for any variety
>of things for which other layouts were defined.
>GBL is not some 'magic pill' that can handle
>all layouts.
>
>(And as an aside, I thought you had gone over to
>using nested layouts, with GBL where appropriate.
>It now seems you are veering back to GBL!)
>
>I doubt you will get GBL working reliably for you
>before learning how a slew of the other layouts
>work, and once you do that, you'll find that you
>use GBL much less often.


Thanks. I did read one of your previous posts on
this very issue and I can see that at least in
case of one of my frames, it is all too true.
Others seemed to work out very nicely, I didn't
even expect it'll end up so good.

I'll try to work on replacing all the gridbags
to something else wherever possible. The only thing
is I would not like to use some proprietary layout
managers or things of that sort. Would like to stick
to standard ones, and, preferrably, not the "latest
and greatest" kind.

I just don't know enough about it and there are
various compatibility issues I'd like to avoid.

I wonder if you might give me a hint on how would
you layout that frame I described in my previous post.
What panels and what layouts would you use
and does the very idea of using nested layouts and
panels make sense?

It seems you'd want to use gridbag on the main frame
and create panels off to group similar things and
try to uses some other layout on each panel wherever
possible.

Thanks again.

>Andrew T.
>

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      01-30-2007
On Jan 30, 9:54 pm, nukl...@invalid.addr (nukleus) wrote:
> In article <1170129146.373308.103...@a75g2000cwd.googlegroups .com>,

....
> I wonder if you might give me a hint on how would
> you layout that frame I described in my previous post.


I might (at least, as well as I understand your description)..

<sscce>
import javax.swing.*;
import java.awt.*;

class ExampleNestedLayout extends JPanel {

ExampleNestedLayout() {
super( new BorderLayout(5,5) );

JToolBar tb = new JToolBar();
// extra measures need to be taken,
// to ensure toolbars can 'float'
// correctly, we keep it simple.
tb.setFloatable(false);
for (int ii=1; ii<5; ii++) {
tb.add( new JButton("Button " + ii ) );
}

add( tb, BorderLayout.NORTH );

JPanel textFieldContainer =
new JPanel(new GridLayout(0,1,5,5));
for (int ii=1; ii<5; ii++) {
textFieldContainer.add( new JTextField() );
}

JPanel textEditContainer = new JPanel(
new BorderLayout(5,5) );
textEditContainer.add(
textFieldContainer, BorderLayout.NORTH );
textEditContainer.add(
new JScrollPane( new JTextArea(5,20) ) );

add( textEditContainer, BorderLayout.WEST );

JPanel checkBoxContainer = new JPanel(
new FlowLayout( FlowLayout.CENTER, 5, 5 ) );
for (int ii=1; ii<15; ii++) {
checkBoxContainer.add(
new JCheckBox("CheckBox " + ii) );
}

add( checkBoxContainer, BorderLayout.CENTER );
}

public static void main(String[] args) {
JFrame f = new JFrame("Example Nested Layout");
f.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(
new ExampleNestedLayout() );
f.pack();
f.setMinimumSize( new Dimension(450,300) );
f.setSize( 800,400 );
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
</sscce>

HTH

Andrew T.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Choosing Layout: Css-Layout or Table-Layout hpourfard@gmail.com ASP .Net 1 06-19-2006 10:06 AM
CSS Layout question - how to duplicate a table layout with CSS Eric ASP .Net 4 12-24-2004 04:54 PM
Oppinion regarding grid layout vs flow layout NWx ASP .Net 4 02-19-2004 08:56 PM
Converting from grid layout to flow layout. RobertH ASP .Net 1 11-04-2003 12:43 AM
DataList inside a Grid Layout Panel (<DIV>) item layout problem Rick Spiewak ASP .Net 3 08-26-2003 04:22 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57