import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by dmarkov on 12/08/16.
 */
public class WindowToBackTest {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                JFrame frame = new JFrame("Frame");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLayout(new FlowLayout());
                frame.setLocation(500, 100);
                frame.setSize(200, 250);
                JButton frameButton = new JButton("To Back");
                frameButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        frame.toBack();
                    }
                });
                frame.add(frameButton);

                JDialog dialog = new JDialog(frame, "Dialog");
                dialog.setLayout(new FlowLayout());
                dialog.setLocation(650, 100);
                dialog.setSize(200, 250);
                JButton dialogButton = new JButton("To Back");
                dialogButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        dialog.toBack();
                    }
                });
                dialog.add(dialogButton);

                frame.setVisible(true);
                dialog.setVisible(true);
            }
        });
    }
}

