Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / October 2005

Tip: Looking for answers? Try searching our database.

jtable add row (without defaultTableModel)

Thread view: 
6e - 05 Oct 2005 20:43 GMT
Hi, im trying to add a row to my custom Table class

the class extends JTable, and based on its contents, I do not believe
that it can successfully use the defaultTableModel's addRow function
because DefaultTableModel causes my application to crash when trying to
insert a JComboBox into one of its cells.

However I am desperately trying to add a row to my JTable using
TableModel....  does anyone have any idea where I may be able to find
help...?

Thanks!
Roedy Green - 05 Oct 2005 23:08 GMT
>the class extends JTable, and based on its contents, I do not believe
>that it can successfully use the defaultTableModel's addRow function
>because DefaultTableModel causes my application to crash when trying to
>insert a JComboBox into one of its cells.

You are missing the fundamental separation of data and display in the
MVC design pattern.  see http://mindprod.com/jgloss/mvc.html


The data value goes into the TableModel, e.g. a String or int..  The
fact that cell is rendered with a JComboBox goes in the
CustomCellRender or CustomCellEditor.

I suppose it is theoretically possible to put a JComboBox in a
datatable, and render it with a custom component that adds it to a
JPanel, but that would be twisting JTable kilometers away from its
original design.

I hope you have one of those fat Swing textbooks to guide you through
this.  

You need to define custom renderers  for your various cells then
register them as the one to use on various columns.

JTable does almost nothing for you. It is just a framework to hang
your code on.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Vova Reznik - 06 Oct 2005 14:52 GMT
> I suppose it is theoretically possible to put a JComboBox in a
> datatable, and render it with a custom component that adds it to a

It is absolutely possible.
If renderer doesn't know how to handle (draw) given class
- it will call toString() and show it.
Example:
javax.swing.JComboBox[,0,0,0x0,invalid,layout=javax.swing.plaf.metal.MetalComboBoxUI$MetalComboBoxLayoutManager,alignmentX=null,alignmentY=null,border=,flags=328,maximumSize=,minimumSize=,preferredSize=,isEditable=false,lightWeightPopupEnabled=true,maximumRowCount=8,selectedItemReminder=]
Roedy Green - 09 Oct 2005 01:03 GMT
>It is absolutely possible.
>If renderer doesn't know how to handle (draw) given class
>- it will call toString() and show it.
>Example:
>javax.swing.JComboBox[,0,0,0x0,invalid,layout=javax.swing.plaf.metal.MetalComboBoxUI$MetalComboBoxLayoutManager,alignmentX=null,alignmentY=null,border=,flags=328,maximumSize=,minimumSize=,preferredSize=,isEditable=false,lightWeightPopupEnabled=true,maximumRowCount=8,selectedItemReminder=]

Which would be a good candidate for best violation of the principle of
least surprise.  Oddly that is not what he was claiming happened. For
some reason his application "crashed" though he has not made clear
what he meant by that.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

HGA03630@nifty.ne.jp - 09 Oct 2005 09:36 GMT
Use table model throughout.
Write a correct renderer/editor for combo box.
See SwingSet2 demo and its source code.
6e - 11 Oct 2005 14:51 GMT
I appreciate all of the help... however I already had the JCombobox
renderer and editor in place.  The piece that I need help with is
adding a new row to the table...

but thanks for the tips..


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.