Layout question

Discussion in 'Java' started by nukleus, Jan 17, 2007.

  1. nukleus

    nukleus Guest

    I am having a lil problem here with someone else old code.
    It uses Frames (all AWT code, no javax stuff).
    and it does not use Layouts.
    When i tried to add a menu, i noticed that it behaves differently
    on different compilers. In some cases some text fields get obscured
    by the menu and things like that.

    Question: can i get away with not using layouts?
    There is a lot of code to rewrite as there are hundreds
    of various user entries setting various parameters.

    Thanx in advance.
     
    nukleus, Jan 17, 2007
    #1
    1. Advertising

  2. nukleus wrote:
    > I am having a lil problem here with someone else old code.
    > It uses Frames (all AWT code, no javax stuff).
    > and it does not use Layouts.


    :-( The person that made that decision, should
    be soundly flogged.

    > When i tried to add a menu, i noticed that it behaves differently
    > on different compilers. In some cases some text fields get obscured
    > by the menu and things like that.


    Null layouts can be broken by being dsiplayed
    on a different OS, or with a VM where the default
    text size is configured larger, or smaller, or
    many other reasons. The code is fundamentally
    flawed and 'fragile'.

    > Question: can i get away with not using layouts?


    ...hmm. Can you afford to lock your end users into
    a particalur VM, with particular font sizes*, on one
    specific OS?

    * Which might cause accessibility problems for
    anyone that requires (e.g.) 'large text'.

    > There is a lot of code to rewrite as there are hundreds
    > of various user entries setting various parameters.


    Yes, but then, as you have already noted - any change to
    this fragile code causes problems, further developement
    of the existing application will cost a great deal more,
    in trying to get the altered code to work 'correctly'.

    Given the complexity of the GUI, it might be better
    to look to a system that generates the GUI 'on-the-fly',
    but uses layouts to achieve the result.

    Andrew T.
     
    Andrew Thompson, Jan 17, 2007
    #2
    1. Advertising

  3. nukleus

    nukleus Guest

    In article <>, "Andrew
    Thompson" <> wrote:
    >nukleus wrote:
    >> I am having a lil problem here with someone else old code.
    >> It uses Frames (all AWT code, no javax stuff).
    >> and it does not use Layouts.

    >
    >:-( The person that made that decision, should
    >be soundly flogged.
    >
    >> When i tried to add a menu, i noticed that it behaves differently
    >> on different compilers. In some cases some text fields get obscured
    >> by the menu and things like that.

    >
    >Null layouts can be broken by being dsiplayed
    >on a different OS, or with a VM where the default
    >text size is configured larger, or smaller, or
    >many other reasons. The code is fundamentally
    >flawed and 'fragile'.
    >
    >> Question: can i get away with not using layouts?

    >
    >...hmm. Can you afford to lock your end users into
    >a particalur VM, with particular font sizes*, on one
    >specific OS?
    >
    >* Which might cause accessibility problems for
    >anyone that requires (e.g.) 'large text'.
    >
    >> There is a lot of code to rewrite as there are hundreds
    >> of various user entries setting various parameters.

    >
    >Yes, but then, as you have already noted - any change to
    >this fragile code causes problems, further developement
    >of the existing application will cost a great deal more,
    >in trying to get the altered code to work 'correctly'.


    That is what i was thinking of.

    >Given the complexity of the GUI, it might be better
    >to look to a system that generates the GUI 'on-the-fly',
    >but uses layouts to achieve the result.
    >
    >Andrew T.


    Thanks for reply.
    I tried to prototype the grid bag layout version and it seems ok.
    One thing i noticed is that the title and menu Y size are not
    accounted for. So, when i layout the gui elements, i have
    to move them all to account for it. Otherwise, in run time
    they get obscured by menu and title.

    The previous code was using addNotify() on the whole frame
    object, which is not allowed, and then using inserts to figure
    out where to start laying things out in run time by adding
    Y offset to all gui elements.

    Do you have any suggestions on what is the best way
    of doing it without wiring in some code that will not be
    recognized by the gui layout designer, such as borland j++?

    Thanks
     
    nukleus, Jan 18, 2007
    #3
  4. nukleus wrote:
    > In article <>, "Andrew
    > Thompson" <> wrote:
    > >nukleus wrote:
    > >> I am having a lil problem here with someone else old code.
    > >> It uses Frames (all AWT code, no javax stuff).
    > >> and it does not use Layouts.

    ....
    > Do you have any suggestions on what is the best way
    > of doing it without wiring in some code that will not be
    > recognized by the gui layout designer, such as borland j++?


    I neither know, nor care, what can be don with some IDE
    (Take that, as an 'Attitude').

    On the other hand, past experience suggests to me
    that the makers of IDE's are smart enough, usually,
    to allow you ways to do what 'needs to be done'.

    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).

    So, even though a GUI is being actively generated,
    it still might be possible to use the usual 'GUI design'
    tools that the IDE offers.

    * The SaverBeans SettingsDialog's are generated
    from XSS based (XML format), settings descriptors.
    The SettingsDialog was designed in the NetBeans
    'form editor'.

    Andrew T.
     
    Andrew Thompson, Jan 18, 2007
    #4
  5. nukleus

    Ian Wilson Guest

    nukleus wrote:
    > I tried to prototype the grid bag layout version and it seems ok.
    > One thing i noticed is that the title and menu Y size are not
    > accounted for. So, when i layout the gui elements, i have
    > to move them all to account for it. Otherwise, in run time
    > they get obscured by menu and title.


    Can you post a small compilable example (an SSCCE) that shows this problem?
     
    Ian Wilson, Jan 18, 2007
    #5
  6. nukleus

    nukleus Guest

    In article <>, "Andrew
    Thompson" <> wrote:
    >nukleus wrote:
    >> In article <>, "Andrew
    >> Thompson" <> wrote:
    >> >nukleus wrote:
    >> >> I am having a lil problem here with someone else old code.
    >> >> It uses Frames (all AWT code, no javax stuff).
    >> >> and it does not use Layouts.

    >....
    >> Do you have any suggestions on what is the best way
    >> of doing it without wiring in some code that will not be
    >> recognized by the gui layout designer, such as borland j++?

    >
    >I neither know, nor care, what can be don with some IDE
    >(Take that, as an 'Attitude').


    Interesting. But what do you do in that case?
    Generate it all on the fly?
    That is what the code i started with was doing,
    using null layout and generating gui elements on the fly.
    But it was just a hack, as even within windows, different
    compilers and versions would produce totally different
    results and that addNotify() trick, used to get the insets
    on a frame object, before it was shown, which is impossible,
    was just a dirty trick, not supported by Sun explicitly.
    But if you have a complex enough layout,
    such as you can create with grid bag, how do you design
    your gui graphically?

    >On the other hand, past experience suggests to me
    >that the makers of IDE's are smart enough, usually,
    >to allow you ways to do what 'needs to be done'.


    True. Actually, what i found out is that the call to
    setLayout was done too late. When i moved it to
    the very beginning of frame initialization code,
    it all seems to work. Not tested it on other compilers yet.
    I don't quite understand all the intricacies of it,
    as this is not the main thing by any means.
    There is so much real stuff to take care of,
    that gui, even though i take a very careful and cautious
    approach in designing, is not the main thing in my case.

    >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?

    >So, even though a GUI is being actively generated,
    >it still might be possible to use the usual 'GUI design'
    >tools that the IDE offers.


    Good. Seems to be the best compromise between
    both words.
    I kinda like borland layout designer, works fine for me
    even for grid bag layout, but i wouln't want to be tied
    up to code it generates, even though it generates
    a perfectly valid code for events, Constraints, etc.
    One thing it does is to to use J... components,
    and ms vj 2003 version does not support javax classes.
    Btw, do you, by any chance, know if i can add javax
    libraries to it? I could not figure out where their classes
    are. There are not configuration parameters i see,
    and i don't even know how to find it. All this "proprietary"
    stuff is simply sickening. It drains so much energy
    and wastes so much stuff on worrying about not getting
    trapped into spider nets they forever weave, it is hard
    to believe.

    Anyway...

    >* The SaverBeans SettingsDialog's are generated
    >from XSS based (XML format), settings descriptors.
    >The SettingsDialog was designed in the NetBeans
    >'form editor'.


    Oh... You got me excited. Thanks.
    I am looking at XML stuff and wrote some code
    to convert the usenet articles into nice looking HTML
    pages or generate an XML code, but i haven't done
    much with XML so far, even though it seems to be
    something worth considering. These standard
    newsreaders seem to be a stone age in terms of gui.

    Where can i see this stuff and how big it is to download?
    Can you tell me?

    Unfortunately, i do not like to get tied up into any
    software manufacturer's proprietary approach and i am
    not looking at netbeans at the moment. Don't even know
    what it is. It is just strictly java stand alone approach.
    Not even meant to be run in any kind of browser or
    whatever those "beans" may want.

    I like the code to work on just about any operating system
    and with just about any compiler out there, going back
    to year 2000 and i am crosschecking my code constantly
    on different compilers and versions to make sure i don't get
    trapped into their proprietary designs and architectures.
    Thats the way i like it. Take it as an attitude :---}

    I have no need to use the javax, which i consider to be
    a booboo on the first place.
    How can you call something extension, if it has exactly the
    same components as the stanard AWT, only slightly improved upon?
    You just fix the bugs and add more functionality to AWT libraries
    instead of creating extensions that are not extensions on the
    first place. And now, with all this arm wresting between
    the ms and sun, on some versions of compilers, javax is
    supported, such as msjv++ 6, and on 2003 version, they are
    abscent altogether. I am not even sure what is the latest version
    of ms java and what does it include and what not.
    When you look at borland compiler, so far, i haven't seen
    a notion of stand alone executable, which means...

    which means that you are going to force your user
    to download gigabytes of stuff from sun or borland
    before they can even run your program. This stuff is
    simply sickening. Sun is also doing its number on screwing
    things up and making it as "proprietary" as impossible.
    So...
    You are kinda walking on a mine field with all their
    "business strategies" of sucking people into their own traps.
    I am simply sick of it all. Looks like, 70% of time you spend not
    on designing and coding, but on worrying what kind of trap
    you may fall into.

    This whole jvm stuff is simply insane, thanks to sun.
    They want it to look like that all the roads to heaven lie
    thru their proprietary trips and, instead of simply making
    a stand alone executable, just like any program out there,
    you have to worry about virtual machines and all that jazz,
    no mortal user would even be interested in hearing about.

    I am running under windows primarily, there is too much
    stuff i have working under it, so i am tied up to it.
    Would love to switch to linux, well,kinda, but some code
    i wrote i device drivers and the linux and window worlds
    are universes appart. Secondly, i am happy with windows
    GUI overall. The last time i looked at linux and all that
    X-stuff, it was kinda stone age level, cludge as it gets.
    Looks kinda ok, but only on the first look.
    But i haven't looked at it lately.

    Anyway, thanks for your feedback.

    >Andrew T.
     
    nukleus, Jan 18, 2007
    #6
  7. nukleus

    nukleus Guest

    In article <>, Ian Wilson
    <> wrote:
    >nukleus wrote:
    >> I tried to prototype the grid bag layout version and it seems ok.
    >> One thing i noticed is that the title and menu Y size are not
    >> accounted for. So, when i layout the gui elements, i have
    >> to move them all to account for it. Otherwise, in run time
    >> they get obscured by menu and title.

    >
    >Can you post a small compilable example (an SSCCE) that shows this problem?


    Well, unfortunately, the original code is gone, but what i did,
    is to move setLayout() from after call to this.setResizable(false);
    to the very top of init routine. Here is what i have now, and it
    seems to be ok. Hopefully that was the problem.

    private void jbInit() throws Exception {

    this.setLayout(gridBagLayout_Frame);

    this.setForeground(new Color(255, 255, 144));
    this.setBackground(new Color(39, 20, 158));
    this.setSize(new Dimension(400, 259));
    this.setTitle(" Set Files");
    this.setResizable(false);

    // Old place of setLayout(
    // this.setLayout(gridBagLayout_Frame);

    this.addComponentListener(new java.awt.event.ComponentAdapter() {
    public void componentResized(ComponentEvent e) {
    this_componentResized(e);
    }
    });
    this.addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    this_windowClosing(e);
    }
    });
    // panel1.setBackground(new Color(210, 255, 255));
    MainPanel.setFont(new java.awt.Font("Dialog", 1, 12));
    MainPanel.setLayout(gridBagLayout_MainPanel);

    ArchiveLabel.setText("Archive");
    AttachmentLabel.setText("Attachment");
    RulesFileLabel.setText("Dictionary");
    QuotesLabel.setText("Quotes");
    AssociationsLabel.setText("Associations");
    IntroLabel.setText("Intro");
    ReminderLabel.setText("Reminder");

    /*
    * the rest of frame init code
    ..................................
    */
    }
     
    nukleus, Jan 18, 2007
    #7
  8. nukleus

    ali Guest

    On Jan 17, 10:28 am, (nukleus) wrote:
    > I am having a lil problem here with someone else old code.
    > It uses Frames (all AWT code, no javax stuff).
    > and it does not use Layouts.
    > When i tried to add a menu, i noticed that it behaves differently
    > on different compilers. In some cases some text fields get obscured
    > by the menu and things like that.
    >
    > Question: can i get away with not using layouts?
    > There is a lot of code to rewrite as there are hundreds
    > of various user entries setting various parameters.
    >
    > Thanx in advance.



    ummm i am not sure but i think the visual editor in Eclipse can help a
    bit

    i read somewhere it can easily convert between null layout to any other
    layout just by simple click

    hope there is some one that have tried it so s/he can support my
    arrgument
     
    ali, Jan 18, 2007
    #8
  9. nukleus wrote:
    > In article <>, "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/browse/jdic/src/incubator/screensaver/src/api/org/jdesktop/jdic/screensaver/SettingsDialog.java?rev=1.5&view=auto&content-type=text/vnd.viewcvs-markup>
    ...and the NetBeans based SettingsDialog.form here..
    <https://jdic.dev.java.net/source/browse/jdic/src/incubator/screensaver/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.
     
    Andrew Thompson, Jan 18, 2007
    #9
  10. ali wrote:
    ....
    > i read somewhere it can easily convert between null layout to any other
    > layout just by simple click


    Probably by converting it to an 'absolute layout' or
    'xy layout' or such, which simply 'locks' components
    into a specific size and position.

    This is probably worse even than a null layout, since
    it might give the (false) impression that the GUI was
    now 'fixed' - whereas it simply had the weaknesses of
    the null layout, combined with the exact positioning
    of the IDE's layout.

    Andrew T.
     
    Andrew Thompson, Jan 18, 2007
    #10
  11. nukleus

    nukleus Guest

    In article <>, "Andrew
    Thompson" <> wrote:
    >nukleus wrote:
    >> In article <>, "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/browse/jdic/src/incubator/screensaver/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/browse/jdic/src/incubator/screensaver/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.
     
    nukleus, Jan 19, 2007
    #11
  12. nukleus

    nukleus Guest

    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.
     
    nukleus, Jan 20, 2007
    #12
  13. 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.
     
    Andrew Thompson, Jan 20, 2007
    #13
  14. nukleus

    nukleus Guest

    In article <>, "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.
     
    nukleus, Jan 21, 2007
    #14
  15. nukleus wrote:
    > In article <>, "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.
     
    Andrew Thompson, Jan 21, 2007
    #15
  16. nukleus

    nukleus Guest

    In article <>, "Andrew
    Thompson" <> wrote:
    >nukleus wrote:
    >> In article <>, "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.
    >
     
    nukleus, Jan 24, 2007
    #16
  17. nukleus

    nukleus Guest

    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.
     
    nukleus, Jan 29, 2007
    #17
  18. On Jan 30, 6:50 am, (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.
     
    Andrew Thompson, Jan 30, 2007
    #18
  19. nukleus

    nukleus Guest

    In article <>, "Andrew
    Thompson" <> wrote:
    >On Jan 30, 6:50 am, (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.
    >
     
    nukleus, Jan 30, 2007
    #19
  20. On Jan 30, 9:54 pm, (nukleus) wrote:
    > In article <>,

    ....
    > 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.
     
    Andrew Thompson, Jan 30, 2007
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick Spiewak
    Replies:
    3
    Views:
    3,167
    Rick Spiewak
    Aug 26, 2003
  2. RobertH
    Replies:
    1
    Views:
    733
    Steve C. Orr [MVP, MCSD]
    Nov 4, 2003
  3. NWx
    Replies:
    4
    Views:
    2,969
    Kevin Spencer
    Feb 19, 2004
  4. Eric
    Replies:
    4
    Views:
    741
    clintonG
    Dec 24, 2004
  5. Replies:
    1
    Views:
    598
    John Timney \(MVP\)
    Jun 19, 2006
Loading...

Share This Page