'Eclipse IDE doesn't read keyboard presses until I click in the console

Right now I'm working on a project with JFrames and the sorts, but whenever I have something that needs to read keyboard clicks, it doesn't start to register them until after I clicked in the Console terminal within the Eclipse IDE. I'm not very well versed in Java and the Eclipse IDE so I'm not sure what's going on. Any help would be apreciated.



Solution 1:[1]

Here is the code for the method. It should open up the panel and then if I hit backspace it should go back to the previous panel.

public void scrapper(Cadet c) throws FontFormatException, IOException {
        frame.remove(panel);
        panel = new Scrapper(c);
        panel.setLayout(null);

        JScrollPane scroll = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

        scroll.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
        scroll.getVerticalScrollBar().setUnitIncrement(30);
        scroll.getHorizontalScrollBar().setUnitIncrement(30);
        frame.add(scroll, BorderLayout.CENTER);

        JButton back = new JButton("");
        back.setBounds(-1, -1, 0, 0);
        back.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.out.println("TEMP");
            }
        });
        back.addKeyListener(new KeyListener() {

            @Override
            public void keyTyped(KeyEvent e) {
            }

            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
                    home();
                }
            }

            @Override
            public void keyReleased(KeyEvent e) {
            }

        });
        panel.add(back);
}

If you need more let me know.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 GamingLegion