user3532043
user3532043

Reputation: 1

Getting the name of JLabel

I have a label in my JFrame. It's variable name is l_1001.

I want to get this variable name in output. How can I do it?

I tried

System.out.print(l_1001.getName())

But output rotates null.

Upvotes: 0

Views: 1615

Answers (1)

Maroun
Maroun

Reputation: 95948

See the docs, JLabel#getName():

Gets the name of the component.

In Java, you cannot simply return the name of the variable (without using reflection), you should set it before, you can use JLabel#setName to do that.

Upvotes: 2

Related Questions