Results 1 to 9 of 9
  1. #1
    amro is offline Member
    Join Date
    Oct 2010
    Posts
    45
    Rep Power
    0

    Question how to control the GridLayout

    in this code

    buttons = new JButton[ 6 ]; // create buttons array
    buttonJPanel = new JPanel(); // set up panel
    buttonJPanel.setLayout( new GridLayout( 1, buttons.length ) );


    every other objects will follow the same layout

    any thing else i insert will fill all the remaining area

    how to disable this and limit the grid layout only to the buttons in the array

  2. #2
    amro is offline Member
    Join Date
    Oct 2010
    Posts
    45
    Rep Power
    0

    Default

    how to control not controlling
    can some one tell me how to modify wrong titles ??

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You will want to next JPanels, with one JPanel that holds the JButtons use GridLayout and another JPanel that holds the button panel use another layout such as BorderLayout. If you need more help, then please read the SSCCE link and create and post one.

    Best of luck!

  4. #4
    amro is offline Member
    Join Date
    Oct 2010
    Posts
    45
    Rep Power
    0

    Default

    thank you for the fast response
    ok i have this code from a book and i need to create a Jtextarea and tow icons and be free to position them any where in the remaining area a and to leave some empty spaces
    but the problem is that the GridLayout will override any thing else's layout

    this is the code from the book where i need to add Jtext area and tow buttons
    with positioning freedom of the buttons grid layout

    Java Code:
    //  PanelFrame.java
    // Using a JPanel to help lay out components.
    import java.awt.GridLayout;
    import java.awt.BorderLayout;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JButton;
    public class PanelFrame extends JFrame
    {
       private JPanel buttonJPanel; // panel to hold buttons
       private JButton buttons[]; // array of buttons
       // no-argument constructor
       public PanelFrame()
       {
          super( "Panel Demo" );
          buttons = new JButton[ 5 ]; // create buttons array
          buttonJPanel = new JPanel(); // set up panel
          buttonJPanel.setLayout( new GridLayout( 1, buttons.length ) );
          // create and add buttons
          for ( int count = 0; count < buttons.length; count++ )
          {
             buttons[ count ] = new JButton( "Button " + ( count + 1 ) );
             buttonJPanel.add( buttons[ count ] ); // add button to panel
          } // end for
          add( buttonJPanel, BorderLayout.SOUTH ); // add panel to JFrame
       } // end PanelFrame constructor
    } // end class PanelFrame

    Java Code:
    //  PanelDemo.java
    // Testing PanelFrame.
    import javax.swing.JFrame;
    public class PanelDemo extends JFrame
    {
       public static void main( String args[] )
       {
          PanelFrame panelFrame = new PanelFrame();
          panelFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
          panelFrame.setSize( 450, 200 ); // set frame size
          panelFrame.setVisible( true ); // display frame
       } // end main
    } // end class PanelDemo

    I wold like to make the frame look as symmetric as possible
    reason : symmetry is the major key of attractiveness

    thank you in advance

  5. #5
    amro is offline Member
    Join Date
    Oct 2010
    Posts
    45
    Rep Power
    0

    Default

    and I would like to create more component in the empty area above the buttons
    this is how it looks:how to control the GridLayout-jframe.png

  6. #6
    amro is offline Member
    Join Date
    Oct 2010
    Posts
    45
    Rep Power
    0

    Default

    this is how my current frame looks like with text area filling all the remaining area

    how to control the GridLayout-staframe.jpg

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Please read the Swing tutorials layout section as it will explain out to use the other layouts. Again, you'll want to nest JPanels, and the best way to learn this well is to experiment with it. Luck!

  8. #8
    amro is offline Member
    Join Date
    Oct 2010
    Posts
    45
    Rep Power
    0

    Default

    thank you

    Again, you'll want to nest JPanels,
    i will go look how this should be done

    and the best way to learn this well is to experiment with it.
    thats what i am doing all of the time but need some guidelines still

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by amro View Post
    thats what i am doing all of the time but need some guidelines still
    And we'll be glad to help. If you run into further difficulty, you might want to post some compilable/runnable code that shows the problem and that we can fiddle with.

    Best of luck!

Similar Threads

  1. SWT GridLayout Demo
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-11-2008, 04:48 PM
  2. control app width based on certain control
    By thebillybobjr in forum SWT / JFace
    Replies: 0
    Last Post: 05-15-2008, 04:52 PM
  3. SWT GridLayout
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-08-2008, 09:04 AM
  4. Use GridLayout in java
    By toby in forum Java Applets
    Replies: 1
    Last Post: 08-04-2007, 12:44 AM
  5. Gridlayout
    By Marty in forum AWT / Swing
    Replies: 2
    Last Post: 05-31-2007, 11:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •