What is java.awt.Component.getName() and setName() used for?

后端 未结 9 1601
半阙折子戏
半阙折子戏 2020-11-28 13:50

What is java.awt.Component.getName() used for? It always seems to be null in the applications I build with NetBeans. I\'m thinking of storing some help text p

9条回答
  •  天命终不由人
    2020-11-28 14:02

    This is what I use getName() for:

        Frame[] frames = JFrame.getFrames();
    
        for (int i = 0; i < frames.length; ++i) {
    
            //get the frame
            Frame frame = frames[i];
    
            if (frame.getName().equals(frameName)) {
    
                //make the frame visible
                frame.setVisible(true);
    
                //focus the frame
                frame.requestFocus();
    
                //found
                return;
    
            }
    
        }
    

提交回复
热议问题