Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: JButtons and Java for 10.5 Update 2



I looked at this problem last week. This fix appeared in 1.5.0_16 as a backport of a fix to 1.6. When the buttons are added to the toolbar, a hierarchyChangedEvent handler will install new borders on the buttons.

My work around was to detect this situation by adding a property change listener to the button. When the property change event is detected, we removed the installed border:

if (UIutils.isMacOS()) {
button.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals("border") && evt.getNewValue() != null) {
AbstractButton b = (AbstractButton)evt.getSource();
b.setBorder(null);
}
}
});
}


You may want to install your own border but you would have to check this type against the PCE.newValue so that you don't get an infinite loop.

--Mark

On 9/25/08 10:33 AM, Michael Brewer-Davis wrote:
Our JButton sizes dramatically wider in Java 1.5 in the new update for
10.5 than they are in (a) Java 1.4 on 10.5 with the new update; (b) Java
1.4 or 1.5 on 10.5 without the new update; (c) Java 1.4 or 1.5 on 10.4
with its new update.  This is (or will shortly be) wreaking havoc with
our application UI for our currently installed user base.

I've put a screenshot showing the difference in our toolbar
buttons at:
http://ers.tech4learning.com/~michael/buttons/FramesInBothJavas.png

The buttons are descendants of JButton, with their UIs descendants of
BasicButtonUI.  The main difference appears to be that the border class
has switched from apple.laf.AquaButtonBorder to
apple.laf.CUIAquaButtonBorder$Dynamic.

We can override this and specify the borders where appropriate to suit
our own needs, but want to make sure we're doing the Right Thing, as
well as to make releasing updates to all of our apps, if necessary, as
smooth as possible.

We originally thought the BasicButtonUI might be at fault--the simple
test case below shows a few pixel difference for button borders by
default.  Clearly we're seeing much more than that.

Any insights?

Thanks,
michael

A test case:
import java.awt.EventQueue;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JToolBar;
import javax.swing.plaf.basic.BasicButtonUI;


public class JButtonBorderTest implements Runnable {
public void run() {
JButton with = new JButton("B");
BasicButtonUI ui = new BasicButtonUI();
with.setUI(ui);


JButton without = new JButton("B");
JToolBar tb = new JToolBar();
tb.add(with);
tb.add(without);
System.out.println(System.getProperty("java.version"));
System.out.println("with");
System.out.println(with.getUIClassID());
System.out.println(with.getUI());
System.out.println(with.getUI().getMinimumSize(with));
System.out.println(with.getUI().getPreferredSize(with));
System.out.println(with.getUI().getMaximumSize(with));
System.out.println("without");
System.out.println(without.getUIClassID());
System.out.println(without.getUI());
System.out.println(without.getUI().getMinimumSize(without));
System.out.println(without.getUI().getPreferredSize(without));
System.out.println(without.getUI().getMaximumSize(without));


        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(tb);
        frame.pack();
        frame.setVisible(true);

        System.out.println("packed");
        System.out.println("with");
        System.out.println(with.getUIClassID());
        System.out.println(with.getUI());
        System.out.println(with.getUI().getMinimumSize(with));
        System.out.println(with.getUI().getPreferredSize(with));
        System.out.println(with.getUI().getMaximumSize(with));
        System.out.println("without");
        System.out.println(without.getUIClassID());
        System.out.println(without.getUI());
        System.out.println(without.getUI().getMinimumSize(without));
        System.out.println(without.getUI().getPreferredSize(without));
        System.out.println(without.getUI().getMaximumSize(without));
}

    public static void main(String[] args) throws Exception {
        EventQueue.invokeAndWait(new JButtonBorderTest());
    }
}


Output on 10.5 with update 2: 10-5-Intel-iMac:Michael kenith$ java JButtonBorderTest 1.5.0_16 with ButtonUI javax.swing.plaf.basic.BasicButtonUI@ba34f2 java.awt.Dimension[width=51,height=25] java.awt.Dimension[width=51,height=25] java.awt.Dimension[width=51,height=25] without ButtonUI apple.laf.CUIAquaButton@19c082 java.awt.Dimension[width=18,height=18] java.awt.Dimension[width=18,height=18] java.awt.Dimension[width=18,height=18] packed with ButtonUI javax.swing.plaf.basic.BasicButtonUI@ba34f2 java.awt.Dimension[width=51,height=25] java.awt.Dimension[width=51,height=25] java.awt.Dimension[width=51,height=25] without ButtonUI apple.laf.CUIAquaButton@19c082 java.awt.Dimension[width=18,height=18] java.awt.Dimension[width=18,height=18] java.awt.Dimension[width=18,height=18]




10-5-Intel-iMac:Michael kenith$ /System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Commands/java JButtonBorderTest 1.4.2_18 with ButtonUI javax.swing.plaf.basic.BasicButtonUI@c247a0 java.awt.Dimension[width=35,height=22] java.awt.Dimension[width=35,height=22] java.awt.Dimension[width=35,height=22] without ButtonUI apple.laf.AquaButtonUI@a31e1b java.awt.Dimension[width=14,height=22] java.awt.Dimension[width=14,height=22] java.awt.Dimension[width=14,height=22] packed with ButtonUI javax.swing.plaf.basic.BasicButtonUI@c247a0 java.awt.Dimension[width=35,height=22] java.awt.Dimension[width=35,height=22] java.awt.Dimension[width=35,height=22] without ButtonUI apple.laf.AquaButtonUI@a31e1b java.awt.Dimension[width=14,height=22] java.awt.Dimension[width=14,height=22] java.awt.Dimension[width=14,height=22]


Output on 10.5 with only update 1: 1.5.0_13 with ButtonUI javax.swing.plaf.basic.BasicButtonUI@2bbd86 java.awt.Dimension[width=47,height=25] java.awt.Dimension[width=47,height=25] java.awt.Dimension[width=47,height=25] without ButtonUI apple.laf.CUIAquaButton@81afa3 java.awt.Dimension[width=14,height=22] java.awt.Dimension[width=14,height=22] java.awt.Dimension[width=14,height=22] packed with ButtonUI javax.swing.plaf.basic.BasicButtonUI@2bbd86 java.awt.Dimension[width=47,height=25] java.awt.Dimension[width=47,height=25] java.awt.Dimension[width=47,height=25] without ButtonUI apple.laf.CUIAquaButton@81afa3 java.awt.Dimension[width=14,height=22] java.awt.Dimension[width=14,height=22] java.awt.Dimension[width=14,height=22] ^CMacintosh-3:Michael managed$



Macintosh-3:Michael managed$
/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Commands/java
JButtonBorderTest
1.4.2_16
with
ButtonUI
javax.swing.plaf.basic.BasicButtonUI@c247a0
java.awt.Dimension[width=35,height=22]
java.awt.Dimension[width=35,height=22]
java.awt.Dimension[width=35,height=22]
without
ButtonUI
apple.laf.AquaButtonUI@a31e1b
java.awt.Dimension[width=14,height=22]
java.awt.Dimension[width=14,height=22]
java.awt.Dimension[width=14,height=22]
packed
with
ButtonUI
javax.swing.plaf.basic.BasicButtonUI@c247a0
java.awt.Dimension[width=35,height=22]
java.awt.Dimension[width=35,height=22]
java.awt.Dimension[width=35,height=22]
without
ButtonUI
apple.laf.AquaButtonUI@a31e1b
java.awt.Dimension[width=14,height=22]
java.awt.Dimension[width=14,height=22]
java.awt.Dimension[width=14,height=22]



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden



This email sent to email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >JButtons and Java for 10.5 Update 2 (From: Michael Brewer-Davis <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.