[Solved] Auto Focus Request Not Working?

Discussion in 'Programming' started by Joedon, May 30, 2016.

  1. Hi here is my JFrame class, but frame.setAutoRequestFocus(true); isn't working. Any ideas?

    Code (Text):
    package com.TutorialGame.main;

    import java.awt.Canvas;
    import java.awt.Dimension;

    import javax.swing.JFrame;

    public class Window extends Canvas{

        private static final long serialVersionUID = 179018054773883690L;

        public Window(int width, int height, String title, Game game){
            JFrame frame = new JFrame(title);
         
            frame.setPreferredSize(new Dimension(width, height));
            frame.setMaximumSize(new Dimension(width, height));
            frame.setMinimumSize(new Dimension(width, height));
         
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setResizable(false);
            frame.setLocationRelativeTo(null);
            frame.add(game);
            frame.setVisible(true);
            //Tried this: not working
            frame.setAutoRequestFocus(true);
         
            game.start();
        }
     
    }
     


    Edit: Fixed - used this.requestFocus() in mwa's updater
     
    #1 Joedon, May 30, 2016
    Last edited: May 30, 2016