Question

No problem making a one-row grid with n columns using GUI Builder, but how do you force GUI builder to make more rows?

Was it helpful?

Solution

Within the container that you want to make the grid, change the layout to a GridLayout.

Then when you select the Gridlayout of that container you can specify the rows and columns and the gaps between them.

See this example: A 3 x 3 grid in a JPanel with no gaps

enter image description here

Then add text boxes (jTextFields) to the panel, results in this

enter image description here

Depending on your use and confidence with java, you may be better off with a JTable


From your comments:

Grid layout tutorial doesn't show how to make rectangular grid and JavaDocs don't address Netbeans

Its not that hard to google "Netbeans GridLayout Tutorial" to find out how to use these with Netbeans.

Like this Video Tutorial

I've never seen the tree diagram shown above with JPanel2 and GridLayout. There's the problem, I think. A bit more detail about how to get the GridLayout-Properties menu would be helpful.

To display the tree view or as its known in Net Beans, Navigator, go to Window -> navigating -> Navigating or Ctrl + 7. This allows you to then easily select the layout of any container by right clicking on the container in the navigator and then selecting Set Layout. You can then right click on the layout and select Properties and then change the rows as needed.

I could set rows and cols to 11 and 11 but THEY DON'T SHOW UP

The rows and columns don't show up for a GridLayout, it is just a layout for other components not a display of rows and columns.

Y'know.... it would be easier to do it by hand and avoid GUIbuilder

Yes, for your example it might have been, but when you try to make a complex Gui the builder is much easier once you know how to use it. And I agree it cannot be intuitive when just starting how to get some of these features to work.

(1) You have to make the JFRAME have GridLayout (and not its cousin container JPanel)

This is not true, you can do it with a JPanel, JDialog or any thing that extends Container

(2) drag JTextFields onto it

You do this with any other container also.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top