B
Brian J. Sayatovic
I'm having a problem with JButton bordersin a JToolBar. I'm making an
aggregate component that is made up of two JButtons in a JPanel. I'd
like to be able to add this to a JToolBar. However, when I do, the
borders of the JButtons do not match the borders of a JButton added
directly to the JToolBar.
Considering the Windows XP look and feel, if you put a JButton in a
JToolBar, the border is not shwon, but mouse-over, etc. works fine. If
I take that same kind of JButton and add it to a JPanel instead, the
XP-style border is shown. So, how can JToolBar turn it off?
I first suspected that maybe it set isBorderPainted to false, but when
I tried that same tactic for the JButton I add to the JPanel, it
didn't eliminate the border. Later I learned that XP actually has a
different image for each state of a button, and a twin set for toolbar
buttons. Inspecting the JToolBar's code, and its corresponding UI
delegate (based on tips in a Javasoft forum), I learned that a JButton
added to a JToolBar has its borders replaced by the JToolBar's
UIManager.
So, for the time being, I've added a 'addToJToolBar' method to my
aggregate component that takes a JToolBar. It then adds the
constituent buttons to the JToolBar so that they'll appear as
expected.
Is there a more graceful solution?
Regards,
Brian.
aggregate component that is made up of two JButtons in a JPanel. I'd
like to be able to add this to a JToolBar. However, when I do, the
borders of the JButtons do not match the borders of a JButton added
directly to the JToolBar.
Considering the Windows XP look and feel, if you put a JButton in a
JToolBar, the border is not shwon, but mouse-over, etc. works fine. If
I take that same kind of JButton and add it to a JPanel instead, the
XP-style border is shown. So, how can JToolBar turn it off?
I first suspected that maybe it set isBorderPainted to false, but when
I tried that same tactic for the JButton I add to the JPanel, it
didn't eliminate the border. Later I learned that XP actually has a
different image for each state of a button, and a twin set for toolbar
buttons. Inspecting the JToolBar's code, and its corresponding UI
delegate (based on tips in a Javasoft forum), I learned that a JButton
added to a JToolBar has its borders replaced by the JToolBar's
UIManager.
So, for the time being, I've added a 'addToJToolBar' method to my
aggregate component that takes a JToolBar. It then adds the
constituent buttons to the JToolBar so that they'll appear as
expected.
Is there a more graceful solution?
Regards,
Brian.