Results 1 to 3 of 3
  1. #1
    nimishalex is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default How to set Document Filter

    I am using JTextField as a render for JTable. I wish to set a doumentfilter on that TextField.Plz help to slove this problem.
    Below is the code i used for rendering.

    -------------------------------------------------------------------------------------
    Java Code:
    class TextFieldRender extends AbstractCellEditor implements TableCellRenderer
    {
    
        JComponent component = new JTextField();
    
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
        {
    
            ((JTextField) component).setText((String) value);
         
            return component;
        }
    
        public Object getCellEditorValue()
        {
    //Doc is my documentFilterClass  
            ((AbstractDocument)((JTextField)component).getDocument()).setDocumentFilter(new Doc());
            return ((JTextField) component).getText();
        }
    }
    ---------------------------------------------------------------------
    But document filter is not working ,,,

    Thanks

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    Mhmm

    my first question is: Why do you implements TableCellRenderer instead of TableCellEditor ? You need a Editor, not a Renderer in my opinion

    second: You have to set the Editor, not the Renderer then.
    table.setDefaultEditor or something like that

    third: Why do you set every time a new DocumentFIlter in getCellEditorValue() ?

    Try: (not tested)
    Java Code:
    class TextFieldRender extends AbstractCellEditor implements TableCellEditor {
    
    	JComponent component = new JTextField();
    	{
    		((AbstractDocument) ((JTextField) component).getDocument()).setDocumentFilter(new Doc());
    	}
    
    	public Object getCellEditorValue() {
    		return ((JTextField) component).getText();
    	}
    
    	@Override
    	public Component getTableCellEditorComponent(JTable table, Object value,
    			boolean isSelected, int row, int column) {
    		((JTextField) component).setText((String) value);
    		return component;
    	}
    }
    And can you show us the code of your DocuementFilter? Maybe the misstake is there too? :)
    Last edited by eRaaaa; 12-27-2010 at 01:42 PM.

  3. #3
    nimishalex is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    Thanks Eraaa ..I am newbie in java.And the code u send me is working perfectly. Here is the link for my DocumentFilter

    "http://www.javaprogrammingforums.com/awt-java-swing/6403-jtextfield-validation.html"



    Thanks once again..
    Last edited by nimishalex; 12-27-2010 at 01:23 PM.

Similar Threads

  1. servlet filter
    By redforce.bala in forum Java Servlet
    Replies: 3
    Last Post: 10-07-2010, 09:21 AM
  2. Pz Help Simple XSL filter
    By Ginouser in forum XML
    Replies: 0
    Last Post: 01-20-2010, 09:20 PM
  3. web content filter or internet filter
    By sundarjothi in forum Advanced Java
    Replies: 3
    Last Post: 05-15-2008, 11:36 AM
  4. Need a filter
    By revathi17 in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •