Hi Vitaliy, This is a Swing bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6176477.
For a work around see the snippet below. Thanks and regards, Janak >-----Original Message----- >From: [EMAIL PROTECTED] >[mailto:[EMAIL PROTECTED] Behalf Of Vitaliy >Tkachenko >Sent: Wednesday, February 07, 2007 6:09 PM >To: Janak Mulani >Cc: [EMAIL PROTECTED] Canoo. Com >Subject: RE: [ULC-developer] Bug found: ULCAlert.setInitialValue doesn't >work > > >Hi, Janak! > >Thanks a lot for response! >But I've enabled "Look and Feel" to Windows mode. And in this case I >expect the same behavior as it is done for the Windows - always both >enter and space keys click the same button. The main behavior difference >is that "default" message box button in windows is focused by default. > >Using the Windows "Look and Feel" mode I have "ok" button pressed by >both enter and space keys and initial value has no effect and no meaning >in this case. I believe this is wrong exactly for "windows" behavior >case, how I can select the "cancel" button by default in this case else? > > >~~~~~~~~~~~~~~~~~~~~~~ >Vitaliy Tkachenko >Senior Software Engineer >Mirasoft > >E-mail: [EMAIL PROTECTED] >Work phone: +380 44 4929960 >Cellular phone: +380 66 7406009 >ICQ: 40299155 >Skype: virtualvat > > --------------------------- import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import javax.swing.JDialog; import javax.swing.JOptionPane; import javax.swing.LookAndFeel; import javax.swing.UIManager; import com.ulcjava.base.application.AbstractAction; import com.ulcjava.base.application.AbstractApplication; import com.ulcjava.base.application.ULCAlert; import com.ulcjava.base.application.ULCBorderLayoutPane; import com.ulcjava.base.application.ULCButton; import com.ulcjava.base.application.ULCFrame; import com.ulcjava.base.application.ULCRootPane; import com.ulcjava.base.application.event.ActionEvent; import com.ulcjava.base.application.event.IWindowListener; import com.ulcjava.base.client.UIAlert; import com.ulcjava.base.development.DevelopmentRunner; public class PR7154 extends AbstractApplication { public void start() { ULCFrame frame = new ULCFrame("ULCTableFocusGainedSnippet"); frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE); frame.getContentPane().add(new ULCButton(new ClickMeAction()), ULCBorderLayoutPane.CENTER); frame.setSize(100, 100); frame.setVisible(true); } public static void main(String[] args) { try { // LookAndFeel laf = new javax.swing.plaf.metal.MetalLookAndFeel(); // LookAndFeel laf = new com.sun.java.swing.plaf.motif.MotifLookAndFeel(); LookAndFeel laf = new com.sun.java.swing.plaf.windows.WindowsLookAndFeel(); UIManager.setLookAndFeel(laf); } catch (Exception e) { e.printStackTrace(); } DevelopmentRunner.setApplicationClass(PR7154.class); DevelopmentRunner.main(args); } private static class ClickMeAction extends AbstractAction { public ClickMeAction() { putValue(NAME, "Show Alert"); } public void actionPerformed(ActionEvent event) { final ULCAlert dialog = new MyULCAlert((ULCRootPane) null, "Test title", "Test message", null); dialog.setFirstButtonLabel("Ok"); dialog.setSecondButtonLabel("Cancel"); dialog.setInitialValue("Cancel"); dialog.addWindowListener(new IWindowListener() { public void windowClosing(com.ulcjava.base.application.event.WindowEvent event) { System.out.println(dialog.getValue()); } }); dialog.show(); } } public static class MyULCAlert extends ULCAlert { protected String typeString() { return MyUIAlert.class.getName(); } public MyULCAlert(ULCRootPane pane, String title, String message, String firstButtonLabel) { super(pane, title, message, firstButtonLabel); } } public static class MyUIAlert extends UIAlert { protected void prepareAlertDialog(final JDialog dialog) { dialog.addWindowListener(new WindowListener() { public void windowActivated(WindowEvent e) { } public void windowClosed(WindowEvent e) { } public void windowClosing(WindowEvent e) { } public void windowDeactivated(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowIconified(WindowEvent e) { } public void windowOpened(WindowEvent e) { JOptionPane optionPane = (JOptionPane) dialog.getContentPane().getComponent(0); optionPane.selectInitialValue(); } }); } } } _______________________________________________ ULC-developer mailing list [email protected] http://lists.canoo.com/mailman/listinfo/ulc-developer
