1 53 package org.swixml; 54 55 import javax.swing.*; 56 import java.awt.*; 57 import java.awt.event.ActionEvent ; 58 import java.awt.event.ActionListener ; 59 import java.awt.event.KeyEvent ; 60 61 67 public class XDialog extends JDialog { 68 86 public XDialog() throws HeadlessException { 87 super( SwingEngine.getAppFrame() != null && SwingEngine.getAppFrame().isDisplayable() ? SwingEngine.getAppFrame() : null ); 88 } 89 90 108 public void show() { 109 this.setLocationRelativeTo( SwingUtilities.windowForComponent( this ) ); 110 super.show(); 111 } 112 113 120 public synchronized void setIconImage( Image image ) { 121 Frame f = JOptionPane.getFrameForComponent( this ); 122 if (f != null && f.getIconImage() == null) { 123 f.setIconImage( image ); 124 } 125 } 126 127 137 protected JRootPane createRootPane() { 138 ActionListener actionListener = new ActionListener () { 139 public void actionPerformed( ActionEvent actionEvent ) { 140 setVisible( false ); 141 } 142 }; 143 JRootPane rootPane = new JRootPane(); 144 KeyStroke stroke = KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ); 145 rootPane.registerKeyboardAction( actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW ); 146 return rootPane; 147 } 148 } 149 | Popular Tags |