0

I'm a beginner and I want to design the gui of the windows calculator in java. I have set some jpanels(Gridlayout) with some jbuttons in each. I set the size of the buttons this way:

jButton[i].setPreferredSize(new Dimension(42, 42));

but buttons in differen jpanels don't have the same size. what should I do?

Mehry
  • 35
  • 4

2 Answers2

1
jButton[i].setPreferredSize(new Dimension(42, 42));

There are 3 easy ways to make buttons larger.

  • Use a big Icon for the button
  • Use a big Font for the button (preferably via a PLAF).
  • Set a large margin around the text and icon.

As to setting the preferred size. See Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing? (Yes.)

If you are still intent on going that route, take the advice of @trashgod and override the preferred size instead.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
0

You should also set the same size for your jpanels

ie. jpanel.setBounds(startingWidth, startingHeight, actualWidth, actualHeight);

and then add these to your container panel.

tas
  • 35
  • 4
  • Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. To organize the components for a robust GUI, instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556), along with layout padding & borders for [white space](http://stackoverflow.com/q/17874717/418556). – Andrew Thompson Apr 25 '14 at 04:07