如何覆写JOptionPane.showInputDialog()方法,要求此对话的显示位置,可以自定义?!!!
还望各位指点!

解决方案 »

  1.   

    public class YourOptionPane extends JOptionPane{}
      

  2.   

    因为JOptionPane实际是封装了一系列JDialog的工厂类(暂且这样理解吧),如果你要实现自定义其显示的对话框,你就得自己实现一个JOptionPane,并且自己定义JDialog下面是JOptionPane的源码:
        public static Object showInputDialog(Component parentComponent,
            Object message, String title, int messageType, Icon icon,
            Object[] selectionValues, Object initialSelectionValue)
            throws HeadlessException {
            JOptionPane    pane = new JOptionPane(message, messageType,
                                                  OK_CANCEL_OPTION, icon,
                                                  null, null);        pane.setWantsInput(true);
            pane.setSelectionValues(selectionValues);
            pane.setInitialSelectionValue(initialSelectionValue);
            pane.setComponentOrientation(((parentComponent == null) ?
        getRootFrame() : parentComponent).getComponentOrientation());        int style = styleFromMessageType(messageType);
            JDialog dialog = pane.createDialog(parentComponent, title, style);//这儿        pane.selectInitialValue();
            dialog.show();
            dialog.dispose();        Object value = pane.getInputValue();        if (value == UNINITIALIZED_VALUE) {
                return null;
            }
            return value;
        }
      

  3.   

    是设置dialog.setSize(xxx,yyy)就可以吗?