Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resizing JButton not working

Status
Not open for further replies.

rekenaar

Technical User
Feb 16, 2005
38
ZA
Hello

I want to set the size of a JButton to be the same as another JButton. Both these buttons are on the same JToolBar.

I use the following:

Code:
private JToolBar createToolBar()
{
  JToolBar m_toolbar = new JToolBar();
  JButton rButton = new JButton(refreshAct);
  JButton pButton = new JButton(printAct);

  m_toolbar.add(rButton);

  // Why isn't this working to set pButton the same size
  // as rButton?
  pButton.setPrefferedSize(rButton.getPreferredSize());

  m_toolbar.add(pButton);

  return m_toolBar;
}

But for some reason the second button doesn't get the same size as the first. It is just as big as it needs to be (Smaller).

Any ideas would be appreciated.

Thanks in advance.
 
I'm not sure what the default layout manager is for JToolBar, but you might try setting it (using JToolBar.setLayout()) to FlowLayout or BoxLayout or something to see if it works better for you. A little trial and error...
 
Thanks. I thought JToolBar would use FlowLayout by default but when i added:
Code:
m_toolBar.setLayout(new FlowLayout(FlowLayout.LEFT));

It worked perfectly by resizing the second button.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top