1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.gui.components.util;
21
22 import java.awt.Container;
23 import java.awt.Window;
24 import java.awt.event.WindowAdapter;
25 import java.awt.event.WindowEvent;
26
27 import javax.swing.JFrame;
28
29
30
31
32
33
34
35
36 public class RunnerHelper {
37
38 public static void runFrame(Window frame, int width, int height) {
39 try {
40 frame.setSize(width, height);
41 frame.addWindowListener(new WindowAdapter() {
42
43
44
45 public void windowClosing(WindowEvent e) {
46 super.windowClosing(e);
47 System.exit(0);
48 }
49 });
50 ComponentPositioner.centerOnScreen(frame);
51 frame.setVisible(true);
52 } catch (Exception e) {
53 System.out.println(">>> Exception in main");
54 e.printStackTrace();
55 }
56 }
57
58 public static void runComponent(Container c, int width, int height) {
59 try {
60
61 JFrame frame = new JFrame(c.getName());
62 frame.setContentPane(c);
63 int w = width + frame.getInsets().left + frame.getInsets().right;
64 int h = height + frame.getInsets().bottom + frame.getInsets().top;
65 runFrame(frame, w, h);
66 } catch (Exception e) {
67 System.out.println(">>> Exception in main");
68 e.printStackTrace();
69 }
70 }
71
72 }