FileDocCategorySizeDatePackage
MiniMizeHack.javaAPI DocExample3720Mon Jan 09 11:01:58 GMT 2006None

MiniMizeHack

public class MiniMizeHack extends Object implements MouseListener, ActionListener

Fields Summary
public JFrame
frame
public JPanel
panel
public JPopupMenu
popup
public JMenuBar
menubar
public JLabel
top
public JLabel
bottom
Dimension
normal_size
Constructors Summary
public MiniMizeHack()

        top = new JLabel(new ImageIcon("image.png"));
        bottom = new JLabel("further info");
        
        frame = new JFrame("Mini Mize Hack");
        panel = new JPanel();
        panel.setLayout(new BorderLayout());
        panel.add("Center",bottom);
        panel.add("North",top);
        frame.getContentPane().add(panel);
        
        
        menubar = new JMenuBar();
        JMenu menu = new JMenu("File");
        menu.add(new JMenuItem("Open"));
        menu.add(new JMenuItem("Quit"));
        menubar.add(menu);
        
        JMenu window = new JMenu("Window");
        JMenuItem mini = new JMenuItem("Minimize");
        mini.addActionListener(this);
        window.add(mini);
        menubar.add(window);
        frame.setJMenuBar(menubar);
        
        
        popup = new JPopupMenu();
        JMenuItem restore = new JMenuItem("Restore");
        restore.addActionListener(this);
        popup.add(restore);
    
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent evt)

        if(bottom.isVisible()) {
            switchToMini();
        } else {
            switchToNormal();
        }
    
public static voidmain(java.lang.String[] args)

        MiniMizeHack mini = new MiniMizeHack();
        mini.frame.pack();
        mini.frame.setSize(300,300);
        mini.frame.setVisible(true);
    
private voidmaybeShowPopup(java.awt.event.MouseEvent e)

        if (e.isPopupTrigger()) {
            popup.show(e.getComponent(),
                       e.getX(), e.getY());
        }
    
public voidmouseClicked(java.awt.event.MouseEvent e)

 
public voidmouseEntered(java.awt.event.MouseEvent e)

 
public voidmouseExited(java.awt.event.MouseEvent e)

 
public voidmousePressed(java.awt.event.MouseEvent e)

        maybeShowPopup(e);
    
public voidmouseReleased(java.awt.event.MouseEvent e)

        maybeShowPopup(e);
    
public voidswitchToMini()

        // nuke the old frame and build a new one
        Point location = frame.getLocation();
        normal_size = frame.getSize();
        frame.setVisible(false);
        frame = new JFrame();
        frame.setUndecorated(true);
        frame.getContentPane().add(panel);
        
        // hide the extra components
        bottom.hide();
        
        // add the popup
        panel.addMouseListener(this);
        
        // stay on top
        //frame.setAlwaysOnTop(true);
        
        // show the frame again
        frame.pack();
        //frame.setSize(100,100);
        frame.setLocation(location);
        frame.setVisible(true);
    
public voidswitchToNormal()

        // nuke the old frame and build a new one
        Point location = frame.getLocation();
        frame.setVisible(false);
        frame = new JFrame();
        frame.setUndecorated(false);
        frame.getContentPane().add(panel);
        
        // show the extra components
        bottom.show();
        frame.setJMenuBar(menubar);
        
        // hide the popup
        panel.removeMouseListener(this);
        
        // turn off stay on top
        //frame.setAlwaysOnTop(false);
        
        // show the frame again
        frame.pack();
        frame.setSize(normal_size);
        frame.setLocation(location);
        frame.setVisible(true);