CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: What to Override?

    If you just subclass DefaultCellEditor and override getTableCellEditorComponent to call the superclass method, then set the font on the Component returned, you don't have to worry about setting the text or overriding getCellEditorValue - the superclass handles that. That's what it's for. You just pass in a JTextField to the constructor and it will use that:
    Code:
    TableCellEditor tce = new DefaultCellEditor(new JTextField()) {
    
        Font ftTxt = new Font("Dialog", Font.PLAIN, 8);
    
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
                                                     int column)
        {
            Component comp = super.getTableCellEditorComponent(table, value, isSelected, row, column);
            comp.setFont(ftTxt);
            return comp;
        }
    };
    Simples...

    When you find yourself repeating lines of code multiple times like that, consider using an array or ArrayList, and looping. Try to remove duplicate code wherever you can.

    Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it in the same way twice...
    C. Alexander
    Last edited by dlorde; January 7th, 2010 at 03:47 PM.
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured