Results 1 to 4 of 4

Thread: Flashing JFrame

  1. #1
    ilyvatar is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Exclamation Flashing JFrame

    Hi,

    I would like to create a JFrame with two specifal features:

    1. JFrame should not grab focus while maximized from minimized state.
    2. When a JFrame created or became maximized from minimized state, it should flash in the Windows bar until a user will grant a focus to it. (like as in ICQ clients ).
    Does anybody know how the second requirement can be implemented?

    Little self-explained example:

    Java Code:
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    
    public class JFrameTest {
        private static JFrame childFrame;
        public static Container getParentContentPane() {
            JPanel panel = new JPanel();
            JButton button = new JButton("Create\\Restore child frame");
            button.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e) {
                    createOrRestoreChildFrame();
                }
            });
            panel.add(button);
            return panel;
        }
    
        private static void createOrRestoreChildFrame() {
            if (childFrame == null) {
                childFrame = new JFrame("Child Frame");
                childFrame.setLocation(200, 200);
                childFrame.add(new JLabel("Child Frame"));
                childFrame.pack();
                setChildFrameVisible();
            } else {
                setChildFrameVisible();
            }
        }
    
        private static void setChildFrameVisible() {
            childFrame.setFocusableWindowState(false);
            childFrame.setVisible(true);
            flashInWindowsBar(childFrame);
            childFrame.toFront();
            childFrame.setFocusableWindowState(true);
        }
    
        /**
         * Should Make child frame flash in Windows bar.
         * Currently, it does not work for me.
         * Could anybody help me to fix this please? ) 
         */
        private static void flashInWindowsBar(JFrame childFrame) {
            childFrame.setState(JFrame.ICONIFIED);
            childFrame.toFront();
        }
    
        private static void createAndShowGUI() {
            JFrame parentFrame = new JFrame("JFrame Demo");
            parentFrame.setLocation(100, 100);
            parentFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            parentFrame.setContentPane(getParentContentPane());
            parentFrame.pack();
            parentFrame.setVisible(true);
        }
    
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
    }
    Thanks!
    Last edited by ilyvatar; 11-30-2010 at 10:17 AM.

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    I have seen this before using a native library and JNI. where this means it is specific to windows, and even the 32 or 64 bit flavor of windows for which the DLL was compiled on.

    see also: 1 2

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

  4. #4
    ilyvatar is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

Similar Threads

  1. MouseListener - Flashing label
    By Adomini in forum New To Java
    Replies: 4
    Last Post: 11-29-2010, 09:31 PM
  2. Replies: 5
    Last Post: 06-14-2010, 06:10 PM
  3. Remove Flashing in Applet
    By Unome in forum Java Applets
    Replies: 5
    Last Post: 05-30-2009, 07:26 PM
  4. Flashing
    By Supamagier in forum Java 2D
    Replies: 6
    Last Post: 04-29-2009, 03:43 PM
  5. Replies: 4
    Last Post: 04-22-2009, 11:02 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •