NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

jTable in netbeans

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
Bøtteknotten



Joined: 23 Aug 2011
Posts: 3

PostPosted: Tue Aug 23, 2011 8:57 pm    Post subject: jTable in netbeans Reply with quote

Hi, I hope this is the right forum for my question.

I'm designing a GUI that contains a table but I cant figure out how to manipulate the table (adding new rows, editing values etc). I've added a simple GUI to this post and I hope someone can demonstrate how I can make the button add an empty row or a row with some values to my table?

According to %29]this page both .addRow and .insertRow should work?



GUI.java
 Description:

Download
 Filename:  GUI.java
 Filesize:  3.56 KB
 Downloaded:  154 Time(s)

Back to top
ebaumann



Joined: 16 Apr 2009
Posts: 108

PostPosted: Wed Aug 24, 2011 10:57 pm    Post subject: Reply with quote

http://download.oracle.com/javase/tutorial/uiswing/components/table.html

Using a DefaultTableModel should work, it notifies the JTable when calling e.g. DefaultTableModel.addRow().
Back to top
Bøtteknotten



Joined: 23 Aug 2011
Posts: 3

PostPosted: Thu Aug 25, 2011 11:08 am    Post subject: Reply with quote

My program already uses the DefaultTableModel.

Code:
jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
Back to top
ebaumann



Joined: 16 Apr 2009
Posts: 108

PostPosted: Thu Aug 25, 2011 9:47 pm    Post subject: Reply with quote

Bøtteknotten wrote:
My program already uses the DefaultTableModel.


And how do you access it? Do you call JTable.getModel() and cast it?
Back to top
Bøtteknotten



Joined: 23 Aug 2011
Posts: 3

PostPosted: Fri Aug 26, 2011 10:29 pm    Post subject: Reply with quote

How would I do that? I've tried:
Code:
jTable1.addRow;

and
Code:
jTable1.insertRow;

but the IDE flags it red.
Back to top
ebaumann



Joined: 16 Apr 2009
Posts: 108

PostPosted: Sat Aug 27, 2011 10:45 pm    Post subject: Reply with quote

You should learn the Java Language and understand what a reference is and what a cast does and so on before implementing a GUI.

You can't call methods which are not defined for that class (or within it's superclass hierarchy or implemented Interfaces): JTable has no methods "addRow()" or "insertRow()", 1. the class' Javadoc tells you that and 2. the IDE autocompletion should not offer one of these methods.

In languages as Java or C++ the compiler tells you an error of that category (as you see in the NetBeans editor window), in some other languages such as Perl you will get an error at runtime.
Back to top
jerry0503222



Joined: 01 Aug 2011
Posts: 14

PostPosted: Wed Sep 07, 2011 7:55 am    Post subject: Reply with quote

Using a DefaultTableModel should work, it notifies the JTable when calling e.g. DefaultTableModel.addRow().








_____________________________
Coach Bags , Coach Outlet , Coach factory outlet
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo