EVALUATION
Notes from java.net user loubs001 on the Swing forum:
Has anyone noticed that toolbar buttons in XP L&F are sized incorrectly? In fact, they're very wrong. Toolbar buttons, say with a 16x16 icon, should be square shaped, which they have been in previous versions of the L&F. But now they are rectangular, far too wide. This has been present since the early builds of Mustang. I guess I should have filed a bug report... I hope this gets fixed soon because not only does the toolbar look strange, but now the buttons are so wide that half of them dont fit in the window anymore.
Now when I report a bug I like to dig in to the Swing sources and find out whats causing it and suggest a fix. But if you're already aware of this problem you can probably skip the rest of this post, otherwise you can read on to hear my take on the subject.
Clearly what's happening is that the toolbar buttons are being sized to what they would be if they were normal buttons, which are rectangular. When buttons get an "acestor" event, XPStyle updates their border. It gives them an XPEmptyBorder with Insets obtained from the UXTheme API using SIZINGMARGINS. This seems like a good idea for truly theme-independant sizing.
For toolbar buttons this creates Insets as [4, 4, 4, 4]. I've checked and these are the correct values. XPEmptyBorder then adds 2 to each of those. Now, a toolbar button with an 6 pixel thick empty border looks great, just right. However these Insets never actually get used since XPEmptyBorder checks the button to see if it's getMargins() is non-null, and if so, uses those instead of the values from Windows. Well, those Margins are always non-null because BasicLookAndFeel sets them to [2, 14, 2, 14]. Obviously those margins were only meant for normal buttons and not toolbar buttons but XPEmptyBorder will use them regardless. Hence, really wide toolbar buttons.
So one solution, the obvious solution, would be to modify XPEmptyBorder so it ignores the Margins for toolbar buttons if they were set by BasicLookAndFeel, eg:
if (c instanceof AbstractButton) {
Insets m = ((AbstractButton)c).getMargin();
if(!(c.getParent() instanceof JToolBar &&
m instanceof InsetsUIResource)) {
margins = m;
}
}
The check for InsetsUIResource would allow the user to override the margins if they wanted, so it shouldnt break anything. So this seems like a good solution, and I was considering getting involved as a contributor and submitting this fix (though I'd prefer it if you guys did it).
But then I thought about it some more, and thought you might want want normal buttons to use native margins aswell, which are also being ignored in favour of Basic's. But unfortunately Windows gives these as (8, 9, 8, 9) which are obviously useless. SIZINGMARGINS are really meant for background stretching and have nothing to do with padding. CONTENTMARGINS on the other hand are given as (3, 3, 3, 3) which might be helpful if combined with margins for padding. But the CONTENTMARGINS for toolbar buttons for some reason are (0, 0, 0, 0) which is no good (they should be 4, 4, 4, 4) so they would need their own margins set separately and... *sigh* you can see how this starts to get complicated =P
I think it would be best to just implement my original simple fix for toolbar buttons and let normal buttons to continue using Basic's margins. They seem to work fine the way they are so why change them.
Anyway, whatever you decide to do, the important thing is that the toolbar buttons need to go back to being square. I hope this gets fixed soon. I'm concerned that if i just file a bug report, it will get put on the back of the queue and wont make it in time for Mustang.
Thanks guys.
|