當前位置: 首頁>>代碼示例>>Java>>正文


Java JTextField.setDocument方法代碼示例

本文整理匯總了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 ) );
        
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:StoreGroupTest.java

示例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 ) );
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:29,代碼來源:StoreGroupTest.java


注:本文中的javax.swing.JTextField.setDocument方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。