• Post Reply Bookmark Topic Watch Topic
  • New Topic

Insets()

 
Savio Mascarenhas
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
Have set the insets of a JButton but even after setting the JButton objects have the same look.
Following is the code used:
trialButton.getInsets().left = 4;
trialButton.getInsets().right = 4;
trialButton.getInsets().top = 4;
trialButton.getInsets().bottom = 4;
Basically need to change the default inner padding of a JButton object.
Pls Suggest.
Thanks Guy's !!!
[This message has been edited by Savio Mascarenhas (edited September 02, 2001).]
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Savio,
I use the following to explicitly set the padding around a JButton

If you want this as default behaviour for all the buttons you create, define a new class that extends JButton and do the above in the new class...that way all your buttons will have the same padding. Something basically like...

Then, when you need a new button, create a new instance of MyJButton, instead of just JButton, and the button will always have the same insets.
e.g.

hope this helps!
Ben.
[This message has been edited by Ben Wood (edited September 03, 2001).]
[This message has been edited by Ben Wood (edited September 03, 2001).]
 
Thomas Suer
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Savio!
If you want to have all buttons in your application look the same way regarding its insets then you could alternatively set the appropriate property of the UIManager (this would be done only once) e.g. before instancing the button component:
UIManager.put("Button.margin", new Insets(4, 4, 4, 4));
If you call it when a component is already displayed you also have to invoke the component's updateUI() method.
Tom
 
Savio Mascarenhas
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben !!!
Thanks ...
 
Savio Mascarenhas
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Thomas
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!