Results 1 to 9 of 9
Thread: how to control the GridLayout
- 10-31-2010, 02:46 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 45
- Rep Power
- 0
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
- 10-31-2010, 02:53 AM #2
Member
- Join Date
- Oct 2010
- Posts
- 45
- Rep Power
- 0
how to control not controlling
can some one tell me how to modify wrong titles ??
-
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!
- 10-31-2010, 12:36 PM #4
Member
- Join Date
- Oct 2010
- Posts
- 45
- Rep Power
- 0
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
- 10-31-2010, 12:51 PM #5
Member
- Join Date
- Oct 2010
- Posts
- 45
- Rep Power
- 0
- 10-31-2010, 01:16 PM #6
Member
- Join Date
- Oct 2010
- Posts
- 45
- Rep Power
- 0
-
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!
- 10-31-2010, 05:37 PM #8
Member
- Join Date
- Oct 2010
- Posts
- 45
- Rep Power
- 0
thank you
Again, you'll want to nest JPanels,
and the best way to learn this well is to experiment with it.
-
Similar Threads
-
SWT GridLayout Demo
By Java Tip in forum SWT TipsReplies: 0Last Post: 07-11-2008, 05:48 PM -
control app width based on certain control
By thebillybobjr in forum SWT / JFaceReplies: 0Last Post: 05-15-2008, 05:52 PM -
SWT GridLayout
By Java Tip in forum Java TipReplies: 0Last Post: 01-08-2008, 10:04 AM -
Use GridLayout in java
By toby in forum Java AppletsReplies: 1Last Post: 08-04-2007, 01:44 AM -
Gridlayout
By Marty in forum AWT / SwingReplies: 2Last Post: 05-31-2007, 12:48 PM
Bookmarks