2
나는 버튼을 아래 코드에있다 "닫기"제목해야 가정,하지만하지 있습니다왜 버튼에 Action 'NAME 속성이 반영되지 않습니까?
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");
}
}
좋은 질문 +1 – mKorbel