Issue with showOkCancelDialog

  6 posts   Feedicon  
Replies: 5 - Last Post: November 05, 2009 08:43
by: mbastian
showing 1 - 6 of 6
 
Posted: June 24, 2009 10:08 by mbastian
Hi !
Firstly, very thank you for this neat library, I appreciate its simplicity and clarity. I'm using it in my application which is built on the top of Netbeans Platform.

I have a small issue with the showOkCancelDialog() method. The created dialog is not centered as it should be.

I've looked at the createDialog() method source, I can tell you that the following line don't return null

Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();


And next the line
result = new JDialog ((Frame) w);


I'm calling the validation panel from a JMenu....

Thanks for your help
 
Posted: July 28, 2009 07:36 by Tim Boudreau
Oops. Will fix.

I was generally thinking of that method as being more for demos than production use, but it may be that people will really use it.

Either way, will fix.

Thanks,

Tim
 
Posted: July 28, 2009 07:39 by Tim Boudreau
Erm, no, looks fine - or perhaps I already fixed it and forgot about it Smile

Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
if (w == null) {
Frame[] f = Frame.getFrames();
w = f == null || f.length == 0 ? null : f[0];
}
JDialog result;
if (w instanceof Frame) {
result = new JDialog ((Frame) w);
} else if (w instanceof Dialog) {
result = new JDialog ((Dialog) w);
} else {
result = new JDialog();
}
if (w != null) {
result.setLocationRelativeTo(w);
}
 
Posted: September 13, 2009 16:59 by mbastian
Though the preceding code looks okay for me I still encounter the problem.

Actually this method is quite useful, because the generated dialog automatically enable/disable the OK button, depending on if it validates or not. When using Netbeans' DialogDescriptor I cannot create this behavior, that's why I'm using this method.

Here is my code which creates the ValidationPanel. InnerPanel is a Netbeans form, using GroupLayout.

ValidationPanel validationPanel = new ValidationPanel();
validationPanel.setInnerComponent(innerPanel);
ValidationGroup group = validationPanel.getValidationGroup();
group.add(.....)
validationPanel.showOkCancelDialog(......)
 
Posted: October 21, 2009 03:06 by Tim Boudreau
FYI, the way to do this with DialogDescriptor is to call setValid().

-Tim
 
Posted: November 05, 2009 08:43 by mbastian
Thanks, it works fine. here is the code snippet


final DialogDescriptor dd = new DialogDescriptor(panel, title);
if (panel instanceof ValidationPanel) {
ValidationPanel vp = (ValidationPanel) panel;
vp.addChangeListener(new ChangeListener() {

public void stateChanged(ChangeEvent e) {
dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
}
});
}
showing 1 - 6 of 6
Replies: 5 - Last Post: November 05, 2009 08:43
by: mbastian
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close