Re: Funky problem with JTable cell rendering

From: Jan Danielsson (
Date: 12/31/04

  • Next message: Andrew Thompson: "Re: Mixing font colors in a JTextArea"
    Date: Fri, 31 Dec 2004 23:56:36 +0100

    Christian Kaufhold wrote:
    >>At this point, I expect to get the most common answer: "You need to
    >>implement getColumClass() in your table model".
    >>I already did that, look:
    >> public Class getColumClass(int col) {
    >> System.out.println("Returning: " + getValueAt(0, col).getClass());
    >> return getValueAt(0, col).getClass();
    >> }
    > The method to override is called "getColumnClass".

    Wadd'ya know! :-) Thanks!

    Makes me wonder: I wonder if those other having the same problem as I
    had copied code from the same webpage as I did?

    > Your implementation is wrong in some places:
    > 1. It will fail with an exception if the TableModel happens to have
    > zero rows at one time.

    How come? When does getColumnClass() get called, other than when there
    are rows?

    > 2. It will give wrong results if the class of the element in the
    > first row is not the same or a superclass of the elements in the
    > other rows, e.g. if the first row contains a String, but the other
    > rows don't all also contain Strings, but other objects.

    This limitation I am aware of, but since the colums are directly mapped
    to columns in an SQL database, that doesn't matter.

    Thanks for spotting that typo..

  • Next message: Andrew Thompson: "Re: Mixing font colors in a JTextArea"

    Relevant Pages

    • Re: XmlSerializer Collection with Collections
      ... > - a bunch of Option objects are contained within an OptionList ... > It is the extra level of object containment in the original version that ... >> public class TestSerializer ... >> public Question(string QuestionText, string Type, int Score, bool ...
    • Re: How to OPEN native PRINTER DIALOG -- Please HELP !!
      ... > function IsNetworkPrinter(PrinterName as string) as boolean ... Public Class YourPrintDialog ... Dim infos As New ArrayList ... ByRef cchBuffer As Int32) As Int32 ...
    • Re: constructors/static methods and inheritance query
      ... public class BaseLine: IBaseLine { ... public static BaseLine Initialize(string x1, string y1, string ... public int keyLength; ...
    • Re: Error : Complex DataBinding accepts as a data source either an IList or an IListSource
      ... > Public Class responseHistoricalData ... > Public equipmentID As String ... > Public proximity() As proximity ... > Private _serviceMeterHours As String ...
    • Re: XmlSerializer Collection with Collections
      ... What you can do here is hide the OptionList from serialization as follows: ... > public class TestSerializer ... > public int AddQuestion(Question question) ... > public Question(string QuestionText, string Type, int Score, bool ...