1

I have an icon button that I want to use with a border. The default border looks too thick.

What's the easiest way to create a border with the same colors as the current look + feel?

Button myButton = createMyIconButton();

...

public Button createMyIconButton()
{
   ...
   setBorder(BorderFactory.createLineBorder(???, 1));
}
Jason S
  • 184,598
  • 164
  • 608
  • 970
  • is there problem extract this border – mKorbel Oct 14 '11 at 21:18
  • 2
    what happens if 1) some L&F on some Native OS doesn't returns any Border, nor LineBorder 2) your idea will be L&F and Native OS sensitive, 3) you didn't wrote I want to extract Border from Nimbus or Metal L&F on Window OS, 4) probably you needed to overide http://download.oracle.com/javase/6/docs/api/javax/swing/plaf/basic/BasicButtonUI.html, but for all possible L&F and Platform, 5) easiest way for MetalButtonUI and Windows OS http://stackoverflow.com/questions/5751311/creating-custom-button-in-java/5755124#5755124, notice, not completed, some painting_effect came from UI and ButtonModel – mKorbel Oct 14 '11 at 21:42

1 Answers1

1

The default border looks too thick.

Maybe you are looking for:

    button.setMargin( new Insets(2, 2, 2, 2) );
camickr
  • 321,443
  • 19
  • 166
  • 288