This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes JTree + JTabel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree + JTabel" Watch "JTree + JTabel" New topic
Author

JTree + JTabel

kannan vinayagam Duraiswamy
Ranch Hand

Joined: Jan 12, 2009
Posts: 52
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...


Kannan.DV
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19672
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
kannan vinayagam Duraiswamy
Ranch Hand

Joined: Jan 12, 2009
Posts: 52
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

Joined: Oct 27, 2005
Posts: 19672
    
  18

What components / layout managers are you using?
kannan vinayagam Duraiswamy
Ranch Hand

Joined: Jan 12, 2009
Posts: 52
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

Joined: Oct 27, 2005
Posts: 19672
    
  18

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

Joined: Jan 12, 2009
Posts: 52



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

Joined: Oct 27, 2005
Posts: 19672
    
  18

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTree + JTabel