Pregunta

There is an Error coming in Find Bugs as follows ,

Method passes constant string to title/label of component

"This method creates a component and passes a string literal to the title or label of the component. As this string will be shown to users, it should be internationalizable through the use of a resource bundle."

The code i have used is :

JMenuItem menuItem = new JMenuItem("Select");

Why is this wrong and how can i fix it.

¿Fue útil?

Solución

You should set values by using set components (properties) to the object than initializing values directly through the constructor.

Eg -

 JLabel mylbl = new JLabel("myName");

You should better to practice to use above syntax as follow

setText(String text) Defines the single line of text this component will display.

JLabel mylbl = new JLabel();
mylbl.setText("myName");

For the More info, refer this

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top