Results 1 to 6 of 6

Thread: JTable Help![Resolved]

  1. #1

    Thread Starter
    Banned debbie_82's Avatar
    Join Date
    Jan 2004
    Location
    inside a hollow void
    Posts
    104

    Question JTable Help![Resolved]

    Can anyone direct me to a site that features creating a custom JTable and custom renderers... Because I'm really having a hard time putting things together with the default JTable...

    Better yet, can anyone give me some ideas in coding JTable...

    I'm so confused already...

    What I wanted to do was to just make the text of the elements in the JTable be smooth using Rendering Hints Text antialiasing but it seems the repaint and validate and revalidate functions are overridden to be noops for performance reasons.
    .



    Tnx.
    Last edited by debbie_82; Jun 8th, 2004 at 03:14 AM.

  2. #2

    Thread Starter
    Banned debbie_82's Avatar
    Join Date
    Jan 2004
    Location
    inside a hollow void
    Posts
    104
    Hey I have worked out the problem but I have a question...


    What's the Result of this statement?


    String.class


    Does this return the class of String?

  3. #3
    New Member njadams's Avatar
    Join Date
    Jun 2004
    Location
    Derby, UK
    Posts
    11
    yes String.class will return the class object of the string class.
    Life is too short for chess!

    http://monkeynick.blogspot.com

  4. #4

    Thread Starter
    Banned debbie_82's Avatar
    Join Date
    Jan 2004
    Location
    inside a hollow void
    Posts
    104
    Originally posted by njadams
    yes String.class will return the class object of the string class.
    But why won't it work when I use it in JTable maybe I'm doing something wrong...

    In JTable I'm using my own cell renderer and my own table model

    to set renderers in JTable you'll have to do like either the following statements right.


    Code:
    table.setDefaultRenderer(table.getModel().getColumnClass(0), new StringRenderer());
    --> This code works fine but


    Code:
    table.setDefaultRenderer(String.class, new StringRenderer());
    --> This code doesn't work...

    Am I right in my assumption that the table.getModel().getColumnClass(0) and the String.class
    should return the same value?...

    But why won't the renderer come out when I use the latter statement? Am I doing something wrong?

    BTW
    in my table model the function getObjectAt always returns a String Object.

  5. #5
    New Member njadams's Avatar
    Join Date
    Jun 2004
    Location
    Derby, UK
    Posts
    11
    Am I right in my assumption that the table.getModel().getColumnClass(0) and the String.class
    should return the same value?...
    Yes and no, they should both return a Class Object.
    However this may not refer to the same class, the String.class returns the Class Object for the String class. unless you have rewritten the method
    Code:
    getColumnClass()
    it will return the Class Object of the Object class.

    Code:
    package testing;
    
    import javax.swing.*;
    
    public class ClassTest
    {
    	public static void main(String[] args)
    	{
    		Class strClass = String.class;
    		System.out.println("strClass.getName() = " + strClass.getName());
    
    
    		JTable tab = new JTable();
    		Class tabClass = tab.getModel().getColumnClass(0);
    		System.out.println("tabClass.getName() = " + tabClass.getName());
    	}
    }
    running this will result in:
    Code:
    String.class = class java.lang.String
    tab.getModel().getColumnClass(0) = class java.lang.Object
    I'm sorry I can't be more help
    Life is too short for chess!

    http://monkeynick.blogspot.com

  6. #6

    Thread Starter
    Banned debbie_82's Avatar
    Join Date
    Jan 2004
    Location
    inside a hollow void
    Posts
    104
    Oh yeah... I didn't override that one... I thought that when I've overridden the getValueAt and returned a String Object it will be ok...

    Thank you for the enlightenment. . You're a great help... Im such a dork sometimes... Thanks a lot.

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