answersLogoWhite

0

You don't actually add items to a LayoutManager object. You should set the layout of the Container you want to add your Components to and the GridLayout will put them where they need to be.

Container myContainer = new Container();

int numRows = 3;

int numCols = 2;

GridLayout myLayoutManager = new GridLayout(numRows, numCols);

myContainer.setLayout(myLayoutManager);

// Add some JButtons to the container...

myContainer.add(new JButtons ("1"));

myContainer.add(new JButtons ("2"));

myContainer.add(new JButtons ("3"));

myContainer.add(new JButtons ("4"));

myContainer.add(new JButtons ("5"));

myContainer.add(new JButtons ("6"));

Your final component will look something like the following:

| 1 | 2 |

| 3 | 4 |

| 5 | 6 |

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

What is GridLayout?

GridLayout organizes a JPanel like a 2-dimensional array (think battleship board game board) so you can easier add items to it in an organized manner


How do you set button size in GridLayout java?

You don't. GridLayout is one of the layout managers that completely ignores all .setSize and .setPreferredSize method calls. If you want to set the size of buttons in a GridLayout, you should add each button to a JPanel, and add the JPanels to the Container with a GridLayout. This way you can use, for example, a FlowLayout on the JPanel and use a button.setPreferredSize method call to try to keep the buttons a particular size.


How do you make login page with java in frame?

To create a login page in Java using a JFrame, you can utilize the Swing library. First, create a new JFrame and set its layout to a suitable manager, like GridLayout or FlowLayout. Add components such as JTextFields for username and password, JLabels for prompts, and a JButton for submission. Implement an ActionListener for the button to handle the login logic, validating user input accordingly.


What are different types of layout manager available in java awt?

A layout manager is an object that is used to organize components in a container.And it is an interface in the java class libraries that describes how a container and a layout manager communicate. There are 5 main Layouts in java :------ 1. FlowLayout 2. BorderLayout 3. CardLayout 4. GridLayout 5. GridbagLayout


How can add java code to java server page?

Scriplet.


Can we add website link when we write java program?

yes ,i can add the website link in java program when we write.


Should you remove java from your computer?

Java is required to download a lot of items from the internet. If you never download anything from the internet, you can remove Java.


Can you add smiley on your java notepad?

yes


What is better Adobe Flash Player or java spript for YouTube?

Java because it lets you do items abode can't do


Is there any way to add items in history in java-script?

If you're in HTML 5 then the history.pushState() method can be used to add an item into the history. Not all the browsers support the method (yet.) You can find out more over at Mozilla (see related link.)


What is the way to get rid of Java lang no class deffound error?

To get rid of the Java lang no class deffound error, one must add the class or .jar file which contains this class into the Java classpath. When a Java class is run from the command line, one must add a dot (.)


How do you save a notepad file into a java file?

just add an extension .java when you save your notepad text file