answersLogoWhite

0

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.

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
RafaRafa
There's no fun in playing it safe. Why not try something a little unhinged?
Chat with Rafa
LaoLao
The path is yours to walk; I am only here to hold up a mirror.
Chat with Lao

Add your answer:

Earn +20 pts
Q: How do you set button size in GridLayout java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you add items in GridLayout in Java?

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 |


What are the steps to increase java heap space on a server?

You can specify the starting and maximum heap sizes when you launch a Java program by using the command line switches: -Xms<size> set initial Java heap size -Xmx<size> set maximum Java heap size Example: The following line will run the MyProgram Java program with 64-128mb heap space. java -Xms64m -Xmx128m MyProgram


What is setDefaultCloseOperation in java programming?

An options that tells a JFrame window what to do when the user click the closeWindow button. Mostly its set to DISPOSE_ON_CLOSE or EXIT_ON_CLOSE. Dispose closes the active window. exit terminates the program.


Who discovered java and when?

java was discovered by James gosling and Co. in 1991 at sun micro systems..they renamed oak to java..initially java used in programming for set top boxes (for movie on demand..)


What is ther role of jre in java?

JRE stands for Java Runtime Environment. JRE is the runtime set up that is required by the JVM to execute java programs. The JRE and JVM (Java Virtual Machine) come packaged along with the Java Development Kit (JDK) that we download and install from the suns website to install Java.