01: package com.pk;
02:
03: import javax.swing.*;
04: import java.awt.*;
05:
06: /** A few utilities that simplify using windows in Swing.
07: * 1998-99 Marty Hall, http://www.apl.jhu.edu/~hall/java/
08: */
09:
10: public class WindowUtilities {
11:
12: /** Tell system to use native look and feel, as in previous
13: * releases. Metal (Java) LAF is the default otherwise.
14: */
15:
16: public static void setNativeLookAndFeel() {
17: try {
18: UIManager.setLookAndFeel(UIManager
19: .getSystemLookAndFeelClassName());
20: } catch (Exception e) {
21: System.out.println("Error setting native LAF: " + e);
22: }
23: }
24:
25: public static void setJavaLookAndFeel() {
26: try {
27: UIManager.setLookAndFeel(UIManager
28: .getCrossPlatformLookAndFeelClassName());
29: } catch (Exception e) {
30: System.out.println("Error setting Java LAF: " + e);
31: }
32: }
33:
34: public static void setMotifLookAndFeel() {
35: try {
36: UIManager
37: .setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
38: } catch (Exception e) {
39: System.out.println("Error setting Motif LAF: " + e);
40: }
41: }
42:
43: /** A simplified way to see a JPanel or other Container.
44: * Pops up a JFrame with specified Container as the content pane.
45: */
46:
47: public static JFrame openInJFrame(Container content, int width,
48: int height, String title, Color bgColor) {
49: JFrame frame = new JFrame(title);
50: frame.setBackground(bgColor);
51: content.setBackground(bgColor);
52: frame.setSize(width, height);
53: frame.setContentPane(content);
54: frame.addWindowListener(new ExitListener());
55: frame.setVisible(true);
56: return (frame);
57: }
58:
59: /** Uses Color.white as the background color. */
60:
61: public static JFrame openInJFrame(Container content, int width,
62: int height, String title) {
63: return (openInJFrame(content, width, height, title, Color.white));
64: }
65:
66: /** Uses Color.white as the background color, and the
67: * name of the Container's class as the JFrame title.
68: */
69:
70: public static JFrame openInJFrame(Container content, int width,
71: int height) {
72: return (openInJFrame(content, width, height, content.getClass()
73: .getName(), Color.white));
74: }
75: }
|