How to get the name of an object in Java?
•
Java
Like this, a = new a (), how do I get a name? (from a) get the string "a"?
A JPanel contains some jtextfields, and a map contains the names of all jtextfields (variable names) I want to set the value of the map to the text of jtextfields
public void mapToJPanel(Map map,JPanel panel) { Component[] compArr = panel.getComponents(); for (Component comp : compArr) { if (comp.getClass().getSimpleName().equals("JTextField")) { JTextField textField = (JTextField) comp; textField.setText(map.get(textField.getName()).toString());//getName() method } } }
Accuss getname() method, I get null-_- I know that the getname () method is not used to get variable names I'm using NetBeans for Java Swing visual development, so I can't rewrite components (such as jtextfield)
Solution
You can use component Setname() names swing and AWT components
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码