RegistryKey.setValue

Overview | Methods | This Package | All Packages

RegistryKey.setValue

Sets the specified value in the registry.

Syntax

public void setValue( String name, Object value )

Parameters

name

A String object that represents the name of value to store data in.

value

The data to store.

Remarks

Use the setValue method  to store information in the specified value. Ensure that the object you assign to value can be restored to its original state. Many of the Windows Foundation Classes for Java provide Editor classes that so you can store the specified class as a string and restore the object from a string.

The following example illustrates how to write a Font object to the registry using the setValue method and the getTextFromValue method. It also shows how to restore the Font object from the registry using the getValue method and the getValueFromText method (Font Editor class).

Font.Editor tempEditor = new Font.Editor();

RegistryKey myKey = Registry.CURRENT_USER.createSubKey("Software\\MyCompany\\MyProduct");

//Store the Font to the registry 
myKey.setValue("MyValue", tempEditor.getTextFromValue(new Font("Arial", 11.0f, FontSize.CHARACTERHEIGHT))); 

//Restore the Font from the registry 
Font myFont = (Font) tempEdit.getValueFromText((String)myKey.getValue("MyValue"));