本文整理汇总了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 ) );
}