本文整理匯總了Java中javax.swing.JTextField.setDocument方法的典型用法代碼示例。如果您正苦於以下問題:Java JTextField.setDocument方法的具體用法?Java JTextField.setDocument怎麽用?Java JTextField.setDocument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JTextField
的用法示例。
在下文中一共展示了JTextField.setDocument方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testString
import javax.swing.JTextField; //導入方法依賴的package包/類
public void testString() throws Exception {
// Test values
String PROP_NAME = "testText";
String ORIGINAL_VALUE = "originalValue";
String NEW_VALUE = "newValue";
// Needed objects
EditableProperties ep = new EditableProperties(false);
PropertyEvaluator evaluator = new PlainPropertyEvaluator( ep );
StoreGroup sg = new StoreGroup();
// Test correct value of the model
ep.setProperty( PROP_NAME, ORIGINAL_VALUE );
Document doc = sg.createStringDocument( evaluator, PROP_NAME );
JTextField jtf = new JTextField();
jtf.setDocument( doc );
assertEquals( "JTextField has to have correct value", ORIGINAL_VALUE, jtf.getText() );
// Test value is stored
jtf.setText( NEW_VALUE );
sg.store( ep );
assertEquals( "Value has to be set into the properties", NEW_VALUE, ep.getProperty( PROP_NAME ) );
}
示例2: testIssue57797
import javax.swing.JTextField; //導入方法依賴的package包/類
/**
*#57797:dist.jar changed to hardcode 'dist' rather than '${dist.dir}'
*/
public void testIssue57797 () throws Exception {
String PROP_NAME_A = "propertyA";
String PROP_NAME_B = "propertyB";
String ORIGINAL_A_VALUE = "original_A_Value";
String ORIGINAL_B_VALUE = "original_B_Value";
String NEW_A_VALUE = "new_A_Value";
EditableProperties ep = new EditableProperties(false);
PropertyEvaluator evaluator = new PlainPropertyEvaluator( ep );
StoreGroup sg = new StoreGroup();
ep.setProperty( PROP_NAME_A, ORIGINAL_A_VALUE );
ep.setProperty( PROP_NAME_B, ORIGINAL_B_VALUE );
Document doc1 = sg.createStringDocument( evaluator, PROP_NAME_A );
Document doc2 = sg.createStringDocument( evaluator, PROP_NAME_B );
JTextField jtf1 = new JTextField ();
jtf1.setDocument ( doc1 );
JTextField jtf2 = new JTextField ();
jtf2.setDocument ( doc2 );
jtf1.setText( NEW_A_VALUE );
EditableProperties newEp = new EditableProperties(false);
sg.store( newEp );
assertEquals( "Expected one new propery", 1, newEp.size());
assertEquals( "Value has to be set into the properties", NEW_A_VALUE, newEp.getProperty( PROP_NAME_A ) );
}