Layouts in Swings

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gaya3
    New Member
    • Aug 2007
    • 184

    Layouts in Swings

    Hi,
    i need one small clarification in swing layouts.
    I done coding as..

    JPanel panel = new JPanel(new new GridLayout(5,0) );
    for(int i=0;i<5;i++)
    {
    panel.add(new JLabel("Label"+ i));
    panel.add(new JButton("button "+i))
    }
    (frame.getConte ntPane()).add(p anel);
    its working fine output is viewed in screen as
    Label1 Button1
    Label2 Button2
    Label3 Button3
    But what i need is
    Label1 Button1
    Label1 Button1
    Label1 Button1
    Button4 Button5 Button6

    is it possible to add button4,button5 ,button6 in another panel and add to the frame?if not how it can be done. Thanks in Advance.

    -Thanks &Regards,
    Hamsa
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by gaya3
    Hi,
    i need one small clarification in swing layouts.
    I done coding as..

    JPanel panel = new JPanel(new new GridLayout(5,0) );
    for(int i=0;i<5;i++)
    {
    panel.add(new JLabel("Label"+ i));
    panel.add(new JButton("button "+i))
    }
    (frame.getConte ntPane()).add(p anel);
    its working fine output is viewed in screen as
    Label1 Button1
    Label2 Button2
    Label3 Button3
    But what i need is
    Label1 Button1
    Label1 Button1
    Label1 Button1
    Button4 Button5 Button6

    is it possible to add button4,button5 ,button6 in another panel and add to the frame?if not how it can be done. Thanks in Advance.

    -Thanks &Regards,
    Hamsa
    I suppose you mean:

    Label1 Button1
    Label2 Button2
    Label3 Button3
    Button4 Button5 Button6

    The first three labels and buttons can be put in a JPanel A having a GridLayout(3, 0)
    The second three Buttons can be put in another JPanel B having a GridLayout(1, 0)
    Put both panels in a third JPanel C having a BorderLayout; put A in the CENTER
    and put B south.

    kind regards,

    Jos

    Comment

    • gaya3
      New Member
      • Aug 2007
      • 184

      #3
      Originally posted by JosAH
      I suppose you mean:

      Label1 Button1
      Label2 Button2
      Label3 Button3
      Button4 Button5 Button6

      The first three labels and buttons can be put in a JPanel A having a GridLayout(3, 0)
      The second three Buttons can be put in another JPanel B having a GridLayout(1, 0)
      Put both panels in a third JPanel C having a BorderLayout; put A in the CENTER
      and put B south.

      kind regards,

      Jos
      Thanks Jos, one more doubt i have..
      i have the output screen with following button display..

      Button1 Button2 Button3 Button4 Button5

      But what i want is

      Button1 Button2
      Button3 Button4 Button5

      where "Button3,Button 4,Button5" needed to display in nextline..
      How can i do that? Thanks in Advance.

      -Thanks & Regards,
      Hamsa

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by gaya3
        Thanks Jos, one more doubt i have..
        i have the output screen with following button display..

        Button1 Button2 Button3 Button4 Button5

        But what i want is

        Button1 Button2
        Button3 Button4 Button5

        where "Button3,Button 4,Button5" needed to display in nextline..
        How can i do that? Thanks in Advance.

        -Thanks & Regards,
        Hamsa
        What do you need all those funny layouts for? Have a look at the GridBagLayout
        or the new SpringLayout layout managers. Also have a look at the invisible components
        (that do take up space) that can be made by the Box class.

        kind regards,

        Jos

        Comment

        Working...