/* (@)PopupFun.java */
/* Copyright 2009 Sebastian Haufe
* Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
[url]http://www.apache.org/licenses/LICENSE-2.0[/url]
* Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
package com.ebenius.swing;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
/**
* Test class for {@link PopupFactory} usage.
*
* @author Sebastian Haufe
*/
public class PopupFun {
/**
* Test main method.
*
* @param args ignored
*/
public static void main(String[] args) {
final JButton button = new JButton(new AbstractAction("Popup") {
public void actionPerformed(ActionEvent e) {
final JScrollPane scrollPane = new JScrollPane(new JTable(7, 2));
scrollPane.getViewport().setBackground(Color.GREEN);
final Point p = MouseInfo.getPointerInfo().getLocation();
final PopupFactory pfac = PopupFactory.getSharedInstance();
final Popup popup =
pfac.getPopup((Component) e.getSource(), scrollPane, p.x, p.y);
popup.show();
final Timer timer = new Timer(5000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
popup.hide();
}
});
timer.setRepeats(false);
timer.start();
}
});
final JPanel contentPane = new JPanel(new BorderLayout(6, 6));
contentPane.add(button);
final JFrame f = new JFrame("Test Frame: PopupFun"); //$NON-NLS-1$
f.setContentPane(contentPane);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.setVisible(true);
}
}