2ronwalf/*
2ronwalf * Created on Oct 30, 2004
2ronwalf */
2ronwalfpackage org.mindswap.utils;
2ronwalf
2ronwalfimport java.awt.Component;
2ronwalfimport java.awt.Dimension;
2ronwalfimport java.awt.Toolkit;
2ronwalfimport java.awt.Window;
2ronwalfimport java.awt.event.ActionEvent;
2ronwalfimport java.awt.event.ActionListener;
2ronwalf
2ronwalfimport javax.swing.BoxLayout;
2ronwalfimport javax.swing.JButton;
2ronwalfimport javax.swing.JComponent;
2ronwalfimport javax.swing.JFrame;
2ronwalfimport javax.swing.JScrollPane;
2ronwalfimport javax.swing.JTextArea;
2ronwalf
2ronwalf/**
2ronwalf * @author Evren Sirin
2ronwalf */
2ronwalfpublic class SwingUtils {
2ronwalf public final static ActionListener windowCloserAction = new ActionListener() {
2ronwalf public void actionPerformed(ActionEvent e) {
2ronwalf JComponent c = (JComponent) e.getSource();
2ronwalf Window w = (Window) c.getTopLevelAncestor();
2ronwalf w.dispose();
2ronwalf }
2ronwalf };
2ronwalf
2ronwalf public static void centerFrame(Window frame) {
2ronwalf Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
2ronwalf Dimension size = frame.getSize();
2ronwalf screenSize.height = screenSize.height/2;
2ronwalf screenSize.width = screenSize.width/2;
2ronwalf size.height = size.height/2;
2ronwalf size.width = size.width/2;
2ronwalf int y = screenSize.height - size.height;
2ronwalf int x = screenSize.width - size.width;
2ronwalf
2ronwalf frame.setLocation(x, y);
2ronwalf }
2ronwalf
2ronwalf
2ronwalf public static void showMessage(String title, String str) {
2ronwalf JFrame info = new JFrame(title);
2ronwalf JTextArea t = new JTextArea(str, 15, 40);
2ronwalf t.setEditable(false);
2ronwalf t.setLineWrap(true);
2ronwalf t.setWrapStyleWord(true);
2ronwalf JButton ok = new JButton("Close");
2ronwalf ok.addActionListener(windowCloserAction);
2ronwalf info.getContentPane().setLayout(new BoxLayout(info.getContentPane(), BoxLayout.Y_AXIS));
2ronwalf info.getContentPane().add(new JScrollPane(t));
2ronwalf info.getContentPane().add(ok);
2ronwalf ok.setAlignmentX(Component.CENTER_ALIGNMENT);
2ronwalf info.pack();
2ronwalf //info.setResizable(false);
2ronwalf centerFrame(info);
3daenzerorama //info.show();
3daenzerorama info.setVisible(true);
2ronwalf }
2ronwalf}