JButton borders in JToolBars with XP look and feel

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.
 
K

Karsten Lentzsch

Brian said:
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.

I follow the same approach.
Is there a more graceful solution?

I would like to add a detection method to the Windows
ToolBarUI that one can refine for such purposes.

Regards,
Karsten
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top