2012-03-24 3 views
2

Ich nehme an Taste sollte hat „Schließen“ Titel im Code unten, aber es hat nicht:Warum zeigt die Schaltfläche NAME-Eigenschaft von Action nicht?

public class Test_Actions extends JDialog 
{ 
    private AbstractAction closeAction = new AbstractAction() 
    {  
     { 
      putValue("NAME", "Close"); 
     } 

     @Override 
     public void actionPerformed(ActionEvent arg0) 
     { 
      Test_Actions.this.setVisible(false); 
      Test_Actions.this.dispatchEvent(new WindowEvent(Test_Actions.this, WindowEvent.WINDOW_CLOSING)); 
     }  
    }; 

    public Test_Actions() 
    {  
     JLabel label = new JLabel("Hello world"); 

     JButton button = new JButton(closeAction); 
     //button.setText("Text"); 

     setLayout(new BorderLayout()); 
     add(label, BorderLayout.CENTER); 
     add(button, BorderLayout.SOUTH); 

     setDefaultCloseOperation(DISPOSE_ON_CLOSE); 

    } 

    public static void main(String[] args) throws InterruptedException, InvocationTargetException 
    { 
     final Test_Actions dialog = new Test_Actions(); 
     dialog.setModal(true); 

     SwingUtilities.invokeAndWait(new Runnable() 
     { 
      @Override 
      public void run() 
      { 
       dialog.pack(); 
       dialog.setVisible(true); 
      }  
     }); 

     System.out.println("Here"); 
    } 
} 
+0

gute Frage +1 – mKorbel

Antwort

8

Verwenden Action.NAME statt "NAME".

Die value of this constant ist eigentlich "Name" also könnten Sie das auch verwenden, aber wie Sie sehen, ist es leicht, es falsch zu verstehen.

+0

Ah ich bin ein Narr! :) – Dims