在全屏独占模式下输入 JtextField 时出现问题

Posted

技术标签:

【中文标题】在全屏独占模式下输入 JtextField 时出现问题【英文标题】:Issue typing in a JtextField in full Screen Exclusive mode 【发布时间】:2013-09-08 10:30:10 【问题描述】:

我想要一个全屏窗口,我可以在其中输入登录名和密码,然后获取登录名并从 textFields 传递。当我在eclipse中运行这段代码时,login textfield和pass textfield无法输入。代码如下:

import java.awt.*; 
import java.awt.event.*;
import javax.swing.*; 
import javax.swing.event.*; 

public class MostrarBloqueio extends JFrame implements ActionListener
 
    private static GraphicsDevice graphicsDevice1;
    private DisplayMode minDisplayMode; 
    private JButton loginButton = new JButton( "login"); 
    private JTextField txtLogin;
    private JPasswordField passwordField;

    public static void main(String[] args)
     //Get and display a list of graphics devices solely for // information purposes. 
        GraphicsEnvironment graphicsEnvironment =  GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = graphicsEnvironment.getScreenDevices(); 
        for(int cnt = 0;cnt < 1;cnt++)
        
            System.out.println(devices[cnt]); 

        //end for loop
    //Construct a full-screen object //
        new MostrarBloqueio(devices[0]);
    //end main



//Constructor 
    public MostrarBloqueio(GraphicsDevice graphicsDevice)
     
        //Save a reference to the graphics device as an // instance variable so that it can be used later to // exit the full-screen mode.  

        this.graphicsDevice1 = graphicsDevice; 
        setTitle("This title will be hidden (undecorated)"); //Get and save a reference to the original display // mode as an instance variable so that it can be // restored later.  
        minDisplayMode = graphicsDevice.getDisplayMode(); 
        loginButton.setBounds(633, 518, 103, 23);

            //Register an action listener on the loginButton.  
        loginButton.addActionListener(this);  
        getContentPane().setLayout(null);

        passwordField = new JPasswordField();
        passwordField.setBounds(633, 475, 142, 20);
        getContentPane().add(passwordField);
        passwordField.setColumns(10);

            //Place the loginButton in the JFrame
        getContentPane().add(loginButton);
        getContentPane().setBackground(getBackground());

        JLabel lblNewLabel = new JLabel("senha:");
        lblNewLabel.setBounds(578, 478, 45, 14);
        getContentPane().add(lblNewLabel);

        JLabel lblLogin = new JLabel("Login:");
        lblLogin.setBounds(578, 456, 45, 14);
        getContentPane().add(lblLogin);

        txtLogin = new JTextField();
        txtLogin.setBounds(633, 453, 142, 20);
        getContentPane().add(txtLogin);
        txtLogin.setColumns(10);        

        if (graphicsDevice.isFullScreenSupported())
         
            // Enter full-screen mode witn an undecorated, // non-resizable JFrame object.  
            setUndecorated(true); 
            setResizable(false);  
            setAlwaysOnTop(true);
            setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            graphicsDevice.setFullScreenWindow(this);
            AltTabStopper at = new AltTabStopper(this);
            at.create(this);
            validate();

        
        else
         
            System.out.println("Full-screen mode not supported");
        //end else 
    //end constructor 

    //The following method is invoked when the used clicks // the loginButton 
    public void actionPerformed(ActionEvent evt)
    
        //Restore the original display mode 
        String login = txtLogin.getText();
        System.out.println("1"+login);
        graphicsDevice1.setDisplayMode(minDisplayMode); 
        //Terminate the program 
        System.exit(0);
    
//end class

【问题讨论】:

您的代码有效...AltTabStopper at = new AltTabStopper(this); at.create(this); 是什么 ***.com/questions/6127709/… 的解决方案使用 alt+tab 禁用切换窗口 我启动了它,但它确实存在问题,显然,JTextField 在单击它后立即失去焦点。 禁用 AltTabStopper 有帮助。 我玩了一下,发现 AltTabStopper 可能无法可靠地工作。 【参考方案1】:

调用 txtLogin.setEditable(true) 和 passwordField.setEditable(true)

【讨论】:

以上是关于在全屏独占模式下输入 JtextField 时出现问题的主要内容,如果未能解决你的问题,请参考以下文章

在全屏 webview 诺基亚 x 中输入视频时出现 NullPointerException

为啥 Direct3D 应用程序在全屏模式下表现更好?

Electron 应用程序 - 如何在全屏模式下禁用/隐藏任务栏中的窗口

在全屏模式下隐藏标题?

MPMoviePlayerController 在全屏模式下停止工作 // 纵向 // iOS 7

在全屏模式下添加 MPMoviePlayerController?