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

  • Home
  • SEARCH
  • 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 7974015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:15:22+00:00 2026-06-04T08:15:22+00:00

I’m trying to implement my own table model to show the schedule in JTable.

  • 0

I’m trying to implement my own table model to show the schedule in JTable. I implemented it, but table even isn’t filled. Maybe I lost some methods which are required to be implemented? Here is my code:

public class ScheduleTableModel extends AbstractTableModel {

    private ArrayList<TimeInterval> timeIntervals;
    private ArrayList<Day> days;
    private LinkedHashMap<ScheduleSlot, Lesson> fullSchedule;
    private LinkedHashMap<ScheduleSlot, Lesson> partialSchedule;
    private ScheduleType scheduleType;


    public ScheduleTableModel(ArrayList<TimeInterval> timeIntervals, ArrayList<Day> days, LinkedHashMap<ScheduleSlot, Lesson> fullSchedule, LinkedHashMap<ScheduleSlot, Lesson> partialSchedule) {
        this.timeIntervals = timeIntervals;
        this.days = days;
        this.fullSchedule = fullSchedule;
        this.partialSchedule = partialSchedule;
        this.scheduleType = ScheduleType.PARTIAL;
        fireTableStructureChanged();
    }

    public ScheduleTableModel(LinkedHashMap<ScheduleSlot, Lesson> fullSchedule) {
        this.fullSchedule = fullSchedule;
        this.scheduleType = ScheduleType.GENERAL;
        fireTableStructureChanged();
    }

    @Override
    public int getRowCount() {
        if (scheduleType == ScheduleType.PARTIAL) {
            return timeIntervals.size() + 1;
        } else {
            return fullSchedule.size();
        }
    }

    @Override
    public int getColumnCount() {
        if (scheduleType == ScheduleType.PARTIAL) {
            return days.size() + 1;
        } else {
            return 3;
        }
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        if (scheduleType == ScheduleType.PARTIAL) {
            if (columnIndex > 0 && rowIndex > 0) {
                for (Map.Entry<ScheduleSlot, Lesson> entry : partialSchedule.entrySet()) {
                    if (entry.getKey().getDay().equals(getColumnDay(columnIndex)) && entry.getKey().getTime().equals(getRowTimeInterval(rowIndex))) {
                        return entry;
                    }
                }
            } else if (rowIndex == 0 && columnIndex > 0) {
                return days.get(columnIndex);
            } else if (columnIndex == 0 && rowIndex > 0) {
                return timeIntervals.get(rowIndex);
            } else if (rowIndex == 0 && columnIndex == 0) {
                return "";
            }
        } else {
            List<Map.Entry<ScheduleSlot, Lesson>> scheduleIterator = new ArrayList<Map.Entry<ScheduleSlot, Lesson>>(fullSchedule.entrySet());
            switch (columnIndex) {
                case 0: {
                    scheduleIterator.get(columnIndex).getKey().getTimeSlot();
                }
                case 1: {
                    scheduleIterator.get(columnIndex).getKey().getPlaceSlot();
                }
                case 2: {
                    scheduleIterator.get(columnIndex).getValue();
                }
            }
        }
        return "";
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    public Day getColumnDay(int columnIndex) {
        return (Day) getValueAt(0, columnIndex);
    }

    public TimeInterval getRowTimeInterval(int rowIndex) {
        return (TimeInterval) getValueAt(rowIndex, 0);
    }

    @Override
    public Class getColumnClass(int columnIndex) {
        if (scheduleType == ScheduleType.GENERAL) {
            switch (columnIndex) {
                case 0: {
                    return fullSchedule.entrySet().iterator().next().getKey().getTimeSlot().getClass();
                }
                case 1: {
                    return fullSchedule.entrySet().iterator().next().getKey().getPlaceSlot().getClass();
                }
                case 2: {
                    return fullSchedule.entrySet().iterator().next().getValue().getGroup().getClass();
                }
                case 3: {
                    return fullSchedule.entrySet().iterator().next().getValue().getProfessor().getClass();
                }
                case 4: {
                    return fullSchedule.entrySet().iterator().next().getValue().getCourse().getClass();
                }

            }
        } else {
            return String.class;
        }
        return String.class;
    }

    @Override
    public String getColumnName(int column) {
        if (scheduleType == ScheduleType.GENERAL) {
            switch (column) {
                case 0: {
                    return "";
                }
                case 1: {
                    return "";
                }
                case 2: {
                    return "";
                }
                case 3: {
                    return "";
                }
                case 4: {
                    return "";
                }
            }
        }
        return "";
    }
}  

Could anybody point me on my mistakes? Thanks everyone in advance!

p.s. I’m not sure if it is necessary to implement setValueAt for Jtable be filled. If I’m right and it is necessary could you show an example of the implementation of this method?

ADDITION:

Implemented setValueAt(), but nothing changed:

@Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        if (scheduleType == ScheduleType.PARTIAL) {
            Map.Entry<ScheduleSlot, Lesson> entry = (Map.Entry<ScheduleSlot, Lesson>) aValue;
            if (columnIndex > 0 && rowIndex > 0) {
                Day day = getColumnDay(columnIndex);
                TimeInterval timeInterval = getRowTimeInterval(rowIndex);
                TimeInterval entryInterval = entry.getKey().getTime();
                Day entryDay = entry.getKey().getDay();
                if (day.equals(entryDay) && timeInterval.equals(entryInterval)) {
                    fullSchedule.put(new ScheduleSlot(new TimeSlot(entry.getKey().getTime(), entry.getKey().getDay()),
                            new PlaceSlot(entry.getKey().getRoom(), entry.getKey().getBuilding())), entry.getValue());
                }
            } else if (rowIndex == 0 && columnIndex > 0) {
                days.add((Day) aValue);
            } else if (columnIndex == 0 && rowIndex > 0) {
                timeIntervals.add((TimeInterval) aValue);
            }
        }

        fireTableDataChanged();
    }  

Here is the picture of tablemodel structure how I see it:

enter image description here

I wanna yellow part be filled from timeIntervals list, green part – from days list and the purpule part – from partialSchedule hashmap.

  • 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-04T08:15:25+00:00Added an answer on June 4, 2026 at 8:15 am
    • your AbstractTableModel missing important setXxx() method(s)

    • why did you use too hard methods fireTableStructureChanged(); use proper fireXxxXxx()methods, this code example contains most of important methods for AbstractTableModel with proper fireXxxXxx()

    • I’d be use DefaultTableModel based on Vector<Vector<Object>> rather than XxxMap or XxxHashMap, this way required depest knowledge about JTable, XxxTableModel and XxxMap or XxxHashMap works together

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.