What is AWT equivalent to JFrame.setDefaultCloseOperation?

We use the setDefaultCloseOperation method (JFrame.EXIT_ON_CLOSE) for the JFrame.

I want to maintain the look and therefore I have to use AWT instead of Swing. So, which AWT method is equivalent to the setDefaultCloseOperation method?

Am I right in thinking that we should use AWT instead of Swing to support appearance?

+3
source share
3 answers

There is no equivalent to one method in AWT, but you can create one yourself.

myFrame.addWindowListener(
  new WindowAdapter(){
    public void windowClosed(WindowEvent e) { System.exit(0); }
  }
);

You can get closer to your original fidelity without using AWT. Instead, set the default “Look and Feel” using the UIManager.

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeel());

, - , - .

+6

Java awt, swing . setDefaultCloseOperation(), swing 7

  public void windowOpened(WindowEvent e)        {   }
  public void windowClosed(WindowEvent e)         {   }
  public void windowActivated(WindowEvent e)     {   }
  public void windowDeactivated(WindowEvent e) {   }
  public void windowIconified(WindowEvent e)      {   }
  public void windowDeiconified(WindowEvent e)   {   }
 public void windowClosing(WindowEvent e)

{}

,

. , , , . , , , Frame (Java ).

,

Frame f = new Frame();
f.addWindowListener(new WindowListener ()
{
    public void windowClosing(WindowEvent we)
    {
        System.exit(0);
    }
});
+1

L'n'F java/javaw -Dswing.defaultlaf.

, Windows -Dswing.defaultlaf = com.sun.java.swing.plaf.windows.WindowsLookAndFeel

.

0

Source: https://habr.com/ru/post/1714464/


All Articles