2012-01-30 10 views
0

以下のようにJOptionPaneに自分のJPanelとJButtonを追加しました。 「OK」ボタンをクリックすると何も表示されません。それに代わるものはありますか?私はちょうどユーザーのユーザー名とパスワードを取得したいが、私のボタンはJOptionpaneのデフォルトではない。 このコードで何が問題になっているかは誰でも確認できますか?JOptionPaneのカスタム作成ボタンが機能しません。

final WebTextField user = new WebTextField(); 
    final WebPasswordField password = new WebPasswordField(); 
    WebButton ok = new WebButton("OK"); 
    ok.addActionListener(new ActionListener() { 
     public void actionPerformed(ActionEvent e) { 
      SwingUtilities.invokeLater(new Runnable() { 
       public void run() { 
        System.out.println("Zip file exist, continuing with extraction of zip file"); 
       } 
      }); 

     } 
    }); 
    WebButton cancel = new WebButton("Cancel"); 
    WebPanel panel = new WebPanel(new GridLayout(2, 2)); 
    panel.setOpaque(false); 
    panel.add(new WebLabel("User:")); 
    panel.add(user); 
    panel.add(new WebLabel("Password:")); 
    panel.add(password); 

    try { 
     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
    } catch (ClassNotFoundException e) { 
     e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 
    } catch (InstantiationException e) { 
     e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 
    } catch (IllegalAccessException e) { 
     e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 
    } catch (UnsupportedLookAndFeelException e) { 
     e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 
    } 
    UIManager.put("OptionPane.background", Color.WHITE); 
    UIManager.put("Panel.background", Color.WHITE); 

    int o =JOptionPane.showOptionDialog(bcfiDownloadPanel, 
      new Object[]{panel}, 
      "Authorization Required", 
      JOptionPane.OK_CANCEL_OPTION, 
      JOptionPane.INFORMATION_MESSAGE, 
      null, 
      new WebButton[]{new WebButton("OK"), new WebButton("Cancel")}, // this is the array 
      "default" 
    ); 
+2

を助けること、[SSCCE](http://sscce.orgを投稿/)。 –

+0

@itro:あなたのキーボードの仕事のプロパティですか?あなたはいつも入力中にあなたのテキストから特定の文字を欠場します。さらに、WebButtonを2回初期化します.1つは提供したコードの始めに、もう1つはshowOptionDIalog()内に1つ作成します。何らかの理由でそれをチェックしてください。わかりませんが、両方が同じものを参照しているようです!よろしく –

答えて

1

非常に珍しいJOptionPaneですが...私は、WebButtonがJButtonを拡張するものであることを願っています。

int o =JOptionPane.showOptionDialog(bcfiDownloadPanel, 
     new Object[]{panel}, 
     "Authorization Required", 
     JOptionPane.OK_CANCEL_OPTION, 
     JOptionPane.INFORMATION_MESSAGE, 
     null, 
     new WebButton[]{new WebButton("OK"), new WebButton("Cancel")}, // this is the array 
     "default" 

...だから、どのJButtonでも、イベントリスナーをクリックするようにアクションリスナーを追加する必要があります。

この方法のようなもので、あなたのコードを変更:

int o =JOptionPane.showOptionDialog(bcfiDownloadPanel, 
      new Object[]{panel}, 
      "Authorization Required", 
      JOptionPane.OK_CANCEL_OPTION, 
      JOptionPane.INFORMATION_MESSAGE, 
      null, 
      new WebButton[]{this.ok, this.cancel}, // this is the array 
      "default" 

レポート早いほど良いのヘルプについて

幸運

関連する問題