954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Making data appear on a JTable?

I'm currently working on a project for my JAVA class. The user picks, from a two dropdown boxes, the times he is busy (military time). And at the bottom of the form, there is a table which displays the times he is busy, and the tables arranges the times from earliest to the latest. Now my question is: How do I do this? Can any one explain? Take note I'm a first time JAVA user, and I'm just practicing to get better. :D

laguardian
Light Poster
28 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

Start with this .

When you have some basics in place, post back with your code and specific questions about the parts that are giving you trouble.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

I made a JTable using NetBeans. I just need to know how to display the chosen items from the combobox in the JTable.

laguardian
Light Poster
28 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

And that is the reason I linked the tutorial. You need to add those items to the table model, which can be a DefaultTableModel or one of your own creation.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

So, here's my code:

ScheduleTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"", null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "User 1 Schedule", "User 2 Schedule", "Free time", "Duration"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }


So, I was thinking that I should replace the:

{"", null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}


to the chosen item from the combo box?
In my combo box, I have about 20 choices. And when the user picks one, it is displayed in the table.

laguardian
Light Poster
28 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

that isn't code, there I missed definitions for JTable, JComboBox, whatever about Swing and your code logics

myTable.getModel().setValueAt(row, column, value);
mKorbel
Veteran Poster
1,141 posts since Feb 2011
Reputation Points: 480
Solved Threads: 224
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: