Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9271225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:34:05+00:00 2026-06-18T15:34:05+00:00

Excuses for asking the same question again. I am under the impression that if

  • 0

Excuses for asking the same question again. I am under the impression that if I added to the original question, I wouldn’t get as many views.

As I’m using an MVC pattern, my Swing GUI is in a different class with the controller creating an instance of it. Here is how I create the table in my View:

tableVehiclePermitHeader = new String[] {"Name", "Expiration Date"};
        tableVehiclePermitData = new Object[0][0];


//      Calendar tempDate = new GregorianCalendar(2008, 1, 1);
//      Date tempDate1 = new Date(2008, 1, 1);
//      tempDate1.setYear(tempDate1.getYear() - 1900);
//      tableVehiclePermitData = new Object [][] {{"Hello", tempDate}, {"Hello", tempDate1}};

        tableVehiclePermitDefaultTableModel = new DefaultTableModel(tableVehiclePermitData, tableVehiclePermitHeader);
        tableVehiclePermit = new JTable(tableVehiclePermitDefaultTableModel){
            public Class getColumnClass(int c) {
                return getValueAt(0, c).getClass();
             }

            public boolean isCellEditable(int rowIndex, int colIndex){
                if (colIndex == 0){
                    return false;
                } else {
                    return true;
                }
            }
        };

        tableVehiclePermit.getColumn("Expiration Date").setCellRenderer(new JDateChooserRenderer());
        tableVehiclePermit.getColumn("Expiration Date").setCellEditor(new JDateChooserCellEditor());

The commented lines show the JDateChooser correctly. It is only when I populate the table content from my view that I’m unable to render dates as JDateChoosers.

Below is my renderer:

public class JDateChooserRenderer extends JDateChooser implements TableCellRenderer{

    Date inDate;

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
        // TODO Auto-generated method stub

        if (value instanceof Date){
            this.setDate((Date) value);
        } else if (value instanceof Calendar){
            this.setCalendar((Calendar) value);
        }
        return this;
    }
}

Finally, my Controller where I get the data to populate the table from a database as an ArrayList of a defined type that has the date fields as type java.util.Date (also tried java.sql.Date to the same result).

ArrayList<VehiclePermitExpirationByVehicleDao> vehPermit = vpmodel.permitExpirationPerVehicle(id);
        VehiclePermitExpirationByVehicleDao permitData;
        permitListData = new Object[vehPermit.size()][3];
        Iterator it = vehPermit.iterator();
        int i = 0;
        while (it.hasNext()){
            permitData = (VehiclePermitExpirationByVehicleDao) it.next();
            permitListData[i][0] = permitData.getVehiclePermitName();
            permitListData[i][1] = permitData.getExpirationDate();
            permitListData[i][2] = permitData.getVehiclePermitId();
            i++;
        }
        gui.setTableVehiclePermitData(permitListData);
        gui.getTableVehiclePermitDefaultTableModel().setDataVector(gui.getTableVehiclePermitData(), gui.getTableVehiclePermitHeader());
        gui.getTableVehiclePermit().setModel(gui.getTableVehiclePermitDefaultTableModel());
        gui.getTableVehiclePermit().setEnabled(true);

Can someone please advise what I’m doing wrong? My suspicion is the type of the column holding the dates.

Also, if anyone had an idea how to go about the editor, kindly let me know.

Regards.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:34:06+00:00Added an answer on June 18, 2026 at 3:34 pm

    You should get TableColumn for the Date column using columnIndex and then set the Renderer and Editor on the TableColumn.

    TableColumn column1 = tableVehiclePermit.getColumnModel().getColumn(1);
    column1.setCellRenderer(new JDateChooserRenderer());
    column1.setCellEditor(new JDateChooserCellEditor());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, so that there are no misunderstandings, while this is the same
This question is a follow-on to another question which needed asking and warranted a
I'm new in JavaScript, so excuse me if this question is not worth asking.
I've tried to really look this one up before asking a question but it
I feel foolish asking such a fundamental question but it would be more foolish
Excuse me for asking such a general question. I'm creating a website with Orchard
I'm a newbie in jQuery, so excuse me for asking such a simple question.
Please excuse my ignorance when asking this question as I am still learning NHibernate
Although I have found several answers to this question I somehow don't get it.
Excuse me if this is a question that has been asked before, if so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.