• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTree + JTabel

 
kannan vinayagam Duraiswamy
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i am developing an application that will load the mib files and shown as tree to the user.
when user select the tree node - its details are shown in jtable.

whats the problem is - the jtable is created when i select a node and the frame is at default size.
when i maximize the frame - the jtable is created but with no values - empty rows

can any one guide me to finish the application please.

any inputs needed please ask me...
 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't recreate the JTable each time. Instead, use a TableModel (DefaultTableModel is the easiest) and simply call setModel when you select a node. That way, you don't need to remove and add JTables each time.

Also, you may want to check out javax.swing.JSplitPane - add a JScrollPane with the JTree on the left, and a JScrollPane with the JTable on the right:

Moving to the Swing forum.
 
kannan vinayagam Duraiswamy
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya Rob I am using a "myOwn" table model that extends AbstractTableModel.
whenever i add a row to the table model i call fireTableDataChanged method.

i have only one tableModel and one jtable.
when user selects the node - i just add rows to the tablemodel.



 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What components / layout managers are you using?
 
kannan vinayagam Duraiswamy
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jtree
defaulttreemodel
jtable
Abstarcttabelmodel

normal borderlaylout

hi rob - i checked the tablemodel after adding the rows - it contains the values - after the complete launch - the jtable has rows but no values get displayed.


 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you do see the table header? Do you call fireTableRowsInserted when you add rows? Do you cann fireTableRowsDeleted when you remove rows (like clear the table)?

fireTableDataChanged is meant for when the contents of multiple cells has changed, as an alternative to fireTableRowsUpdated.
 
kannan vinayagam Duraiswamy
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



in the add method



but still i am able to see rows - but with no values in it

i seen the fireTableRowsInsterted method in that - it create a tablemodelevent and send to its listeners -
but in my table model i didnt declare any tablemodel listener - is it mandatory to declare a table model listener?

 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JTable is its own TableModelListener. It will attach itself to the model when you call getModel() - either directly or by specifying the model in the JTable constructor.

I really hope your displayNodeDetails is a LinkedHashMap, because otherwise you're lying to the listeners. You're telling them that you added an element at the end but for a HashMap or TreeMap that's certainly not the case.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic