3

Is there some way to have a set of JButton objects that aren't in a standard 'Grid' shape? I'm specifically looking to make a set of buttons that are different shapes and sizes, like the bottom two rows of the Microsoft Calculator.

Here is an example of what I want the buttons to look like:

Bottom two rows, Microsoft Calculator

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Salmononius2
  • 295
  • 5
  • 14
  • 4
    [`GridBagLayout`](http://docs.oracle.com/javase/tutorial/uiswing/layout/gridbag.html) could easily create that layout. – Andrew Thompson May 01 '15 at 14:13
  • Just to avoid the problems with layout adjustments, and concentrate more on application logic, its better to use some third party libraries like http://www.miglayout.com/. – K139 May 01 '15 at 14:16
  • 1
    @K139 In order to avoid problems with the run-time class path and the size of the distributable, **use J2SE layouts!** – Andrew Thompson May 01 '15 at 14:27
  • @AndrewThompson Agreed! – K139 May 01 '15 at 14:34
  • There is also the option of [`GroupLayout`](https://docs.oracle.com/javase/tutorial/uiswing/layout/group.html), but before I get kicked out of here for mentioning this option, I would just like to-- – user1803551 May 01 '15 at 19:47

1 Answers1

2

GridBagLayout is natural choice for requested layout. You can spread buttons evenly, occupy range of cells or even choose size for each particular cell. Here is good example.

Alex
  • 4,457
  • 2
  • 20
  • 59