Results 1 to 3 of 3
  1. #1
    Macamba is offline Member
    Join Date
    Aug 2015
    Posts
    2
    Rep Power
    0

    Default Time field in JTable

    If I understand correctly, you should enter field specific data in your JTable to get some input checking in your JTable. I'm trying to get Time data into a field and failing.

    In my application I read my records from the database into the JTable. This table is put into a JScrollPane which is put in the JPanel of the class.

    [code]
    Java Code:
    public class MyRecordsPanel extends JPanel implements TableModelListener, ActionListener {
    	public JPanel createRecordsPanel(LocalDate theDate) {
    		Vector <object> data = getTableData(data, columns, monday);
    	}
    
    	private Vector<Object> getTableData(Vector<Object> data, int columns, LocalDate monday) {
    		Vector<Object> row;
    
    		// Read projects for this date from the database
    		projects = getProjects(user.getPersonIdentifier(), monday);
    
    		// Translate the contents of the projects of this week to the Vector data
    		Project project;
    		int size = projects.size();
    		int i = 0;
    		while (i < size) {
    			row = new Vector<Object>(columns);
    			project = projects.get(i);
    
    			// Find week day (ma, di, .. , zo) based on date
    			weekdayNumber = weekDayNumberFormatter.format(project.getDate());
    			weekday = weekDayFormatter.format(project.getDate());
    			row.addElement(weekday);
    
    			// Find date
    			LocalDate datum = project.getDate().toLocalDate();
    			row.addElement(datum.format(localDateFormatter));
    
    			row.addElement(project.getProjectNumber());
    			row.addElement(project.getProjectName());
    			row.addElement(project.getActivity());
    			//logState (INFO, "getTableData: project.getTime(): " + project.getTime()); 
    			//row.addElement((project.getTime()));
    			//row.addElement(((Time) project.getTime()).toString());
    			
    			Time time = project.getTime();
    			logState (INFO, "getTableData: time=" + time); 
    			row.addElement(time);
    
    			data.addElement(row);
    
    			i++;
    		}
    		return data;
    	}
    If I understand correctly you should add elements type specific (e.g. as String, int, Date) to the fields. Therefore I'm trying to get the sql time from my database as time into the table. However, I only succeed to get it as String in the table.

    Java Code:
    logState (INFO, "getTableData: project.getTime(): " + project.getTime()); 
    row.addElement((project.getTime()));
    Output:
    getTableData: time=01:15:00
    getTableData: time=04:15:00
    But the table displays "1-jan-1970". And the cell is uneditable.

    I originally had (in lines 32 and 34):
    Java Code:
    logState (INFO, "getTableData: project.getTime(): " + project.getTime()); 
    row.addElement(((Time) project.getTime()).toString());
    Output:
    getTableData: project.getTime(): 01:15:00 
    getTableData: project.getTime(): 04:15:00
    Now the table displays "01:15:00" and I can edit the cell. And I can enter what I want in the cell because the CellRenderer thinks I'm entering a String.

    What should I do?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Time field in JTable

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Macamba is offline Member
    Join Date
    Aug 2015
    Posts
    2
    Rep Power
    0

    Default Re: Time field in JTable

    Thanks Darryl for finding this post on another forum. But does this post have the answer to my problem?

Similar Threads

  1. Replies: 5
    Last Post: 09-06-2014, 04:26 PM
  2. JTable Not Updating in Real Time
    By steme in forum New To Java
    Replies: 1
    Last Post: 06-13-2013, 10:04 PM
  3. Filling Text Field from information from JTable
    By Dcalladi in forum AWT / Swing
    Replies: 3
    Last Post: 10-20-2011, 05:12 PM
  4. insert data from text field to jtable
    By mackinas in forum New To Java
    Replies: 2
    Last Post: 06-09-2010, 04:30 AM
  5. Adding Hyperlinks/Links inside a field of a JTable
    By javanewbie in forum AWT / Swing
    Replies: 3
    Last Post: 05-31-2009, 04:19 AM

Posting Permissions

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