Frage

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.

War es hilfreich?

Lösung

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top