vedran
vedran

Reputation: 2188

How to set JButton width through percentage?

I'm looking for a way to set the width of a JButton to match the width of the cell it's currently located in. I have 3 cells, each with a button, but the button size varies. I used to work a little bit with html, so all I had to do is add % at the end of variable. How can I do that for JButton?

EDIT: Just in case someone else is looking for the solution. MigLayer allows usage of percents, but I found something more soothing to my needs:

MigLayout("", "[grow, fill]", "[]")

EDIT2: As requested here's the screenshot of desired effect:

enter image description here

link to screenshot

Upvotes: 2

Views: 2805

Answers (3)

mKorbel
mKorbel

Reputation: 109813

There are three ways:

  1. BoxLayout
  2. BorderLayout
  3. todays Miglayout

Upvotes: 2

Boris Pavlović
Boris Pavlović

Reputation: 64632

Vedrane,

MigLayout allows for using percantages as a unit of measure

Upvotes: 4

Andrew Thompson
Andrew Thompson

Reputation: 168825

This can probably be achieved by adding the buttons to a single row GridLayout.

Upvotes: 2

Related Questions