Results 1 to 3 of 3
  1. #1
    KArelVH is offline Member
    Join Date
    Apr 2009
    Posts
    6
    Rep Power
    0

    Default JFrame toFront() not working

    Hey,

    I'm quite new to java and I'm making a rather big project.

    In the project I have a JMenuBar with a JMenu which keeps track of all opened windows. When, in that menu, I click on a JMenuItem, the corresponding JFrame should pop to the foreground. For this I use the toFront() method.

    However, only the titlebar lightens up but the frame doesn't come to the foreground.

    Does anyone know what the problem can be?

    **will edit this post with a screenshot and code snippet in a minute, stupid me is typing this post on a different PC :p **

    code:
    Java Code:
    public class MyJMenu extends JMenu implements ChangeListener{
        
        private HeadMenuModel model;
    
        public MyJMenu(String text, HeadMenuModel model){
            super(text);
            this.model = model;
    
            maakMenu();
            model.addChangeListener(this);
    
        }
    
        public void stateChanged(ChangeEvent e) {
           maakMenu();
        }
    
        public void maakMenu(){
            if(model.getWindows().size() == 0){
                setEnabled(false);
            }
            else{
                removeAll();
                setEnabled(true);
                for(Window i : model.getWindows()){
                    JMenuItem item = new JMenuItem(i.getNams());
                    item.addActionListener(new FocusListener(i));
                    add(item);
                }
            }
        }
    
        private class FocusListener implements ActionListener{
            private Window venster;
    
            public FocusListener(Window i){
                this.venster = i;
            }
    
            public void actionPerformed(ActionEvent e) {
                venster.toFront();
            }
    
        }
    
    }
    Last edited by KArelVH; 04-14-2009 at 02:38 PM.

  2. #2
    KArelVH is offline Member
    Join Date
    Apr 2009
    Posts
    6
    Rep Power
    0

    Default

    solved.
    Apparently the toFront method doesn't work if your visual effects aren't on in ubuntu.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    What if you used JDialogs here instead of JFrame and called setVisible(true/false) as needed?

Similar Threads

  1. Help in JFrame
    By kirtesh4u in forum New To Java
    Replies: 2
    Last Post: 11-18-2008, 01:40 AM
  2. help in JFrame
    By kirtesh4u in forum AWT / Swing
    Replies: 1
    Last Post: 11-18-2008, 01:26 AM
  3. SquareRoot Jframe semi working
    By 2o2 in forum AWT / Swing
    Replies: 6
    Last Post: 09-29-2008, 04:20 AM
  4. Replies: 8
    Last Post: 05-28-2008, 08:00 AM
  5. Working With ANT
    By JavaForums in forum Eclipse
    Replies: 0
    Last Post: 04-26-2007, 09:16 PM

Posting Permissions

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