All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.com.toedter.calendar.demo.DemoTable Maven / Gradle / Ivy

Go to download

JCalendar is a Java date chooser bean for graphically picking a date. JCalendar is composed of several other Java beans, a JDayChooser, a JMonthChooser and a JYearChooser. All these beans have a locale property, provide several icons (Color 16x16, Color 32x32, Mono 16x16 and Mono 32x32) and their own locale property editor. So they can easily be used in GUI builders. Also part of the package is a JDateChooser, a bean composed of an IDateEditor (for direct date editing) and a button for opening a JCalendar for selecting the date.

The newest version!
/*
 *  DemoTable.java  - A table to demo JDateChooser cell editors.
 *  Copyright (C) 2006 Kai Toedter
 *  [email protected]
 *  www.toedter.com
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

package com.toedter.calendar.demo;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.util.Date;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;

import com.toedter.calendar.JDateChooserCellEditor;

/**
 * A demonstration table with JDateChooserCellEditors.
 * 
 * @author Kai Toedter
 * @version $LastChangedRevision: 119 $
 * @version $LastChangedDate: 2009-05-04 17:47:56 +0200 (Mo, 04 Mai 2009) $
 */
public class DemoTable extends JPanel {
	private static final long serialVersionUID = -2823838920746867592L;

	public DemoTable() {
		super(new GridLayout(1, 0));

		setName("DemoTable");

		JTable table = new JTable(new DemoTableModel());
		table.setPreferredScrollableViewportSize(new Dimension(180, 32));
		table.setDefaultEditor(Date.class, new JDateChooserCellEditor());

		// Create the scroll pane and add the table to it.
		JScrollPane scrollPane = new JScrollPane(table);

		// Add the scroll pane to this panel.
		add(scrollPane);
	}

	class DemoTableModel extends AbstractTableModel {
		private static final long serialVersionUID = 3283465559187131559L;

		private final String[] columnNames = { "Empty Date", "Date set" };

		private final Object[][] data = { { null, new Date() },
				{ null, new Date() } };

		public int getColumnCount() {
			return columnNames.length;
		}

		public int getRowCount() {
			return data.length;
		}

		public String getColumnName(int col) {
			return columnNames[col];
		}

		public Object getValueAt(int row, int col) {
			return data[row][col];
		}

		/*
		 * JTable uses this method to determine the default renderer/ editor for
		 * each cell. If we didn't implement this method, then the last column
		 * would contain text ("true"/"false"), rather than a check box.
		 */
		public Class getColumnClass(int c) {
			return getValueAt(0, 1).getClass();
		}

		/*
		 * Don't need to implement this method unless your table's editable.
		 */
		public boolean isCellEditable(int row, int col) {
			return true;
		}

		/*
		 * Don't need to implement this method unless your table's data can
		 * change.
		 */
		public void setValueAt(Object value, int row, int col) {
			data[row][col] = value;
			fireTableCellUpdated(row, col);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy