wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes how to add JCombox inside JtreeTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to add JCombox inside JtreeTable" Watch "how to add JCombox inside JtreeTable" New topic
Author

how to add JCombox inside JtreeTable

Siddharth Mehrotra
Ranch Hand

Joined: Aug 21, 2001
Posts: 185
Hi,
I have been struggling to add a jcomboox inside a jtreetable.
can anyone assist me with some code snippet.


SCJP, SCJD.
sachin pathak
Greenhorn

Joined: Jun 05, 2002
Posts: 27
Originally posted by Siddharth Mehrotra:
Hi,
I have been struggling to add a jcomboox inside a jtreetable.
can anyone assist me with some code snippet.

I could not get your question properly, but if it is somewhat like this
" I want to add a JComboBox inside a JTree or JTable" then the solution is easy.
Create a custom table model and custom CellRenderer. from the getXxxRendererComponent() method of the renderer, return a JComboBox as a renderer. If you want this JComboBox to be editable then there is lot of work that needs to be done. In addition to create arenderer, you will need to create a custom editor component, and use is as a editor for your tree or table. Return the JComboBox from the method getXxxEditorComponent, you can find the details in core JAva vol-2 or the best source is Graphic Java (Swing Volume, i dont recall the volume number).
MVC will take care of all other factors.
It is these kinds of situations which makes java score over microsoft technologies.
Siddharth Mehrotra
Ranch Hand

Joined: Aug 21, 2001
Posts: 185
hi sachin,
you have given some light to what my problem is,
actually when i said treetable, it is a table where i have set a tree renderer for one column, so i have a jtree inside i a jtable.
so eventually i feel i need a cellrenderer for jcombobox, you have mentioned a method in your statement can you, elaborate more on that with respect to JTable.
Siddharth Mehrotra
Ranch Hand

Joined: Aug 21, 2001
Posts: 185
hi sachin ,
I have been able to add the combobox,
but it is not working, i mean i can see the first element, but when i expannd the combo i dont see any data of the combo, and after collapsing the combo it gets back to the same, state showing the first element.

let me tell you what i have done,
I created the combobox insside the method getTableCellRendererComponent,
and returned it.
is it right, i guess i will have to modify the getvalueat and setvalueta methods also, but i have no clue as to how shoud i modify the same, for using combobox.
sachin pathak
Greenhorn

Joined: Jun 05, 2002
Posts: 27
is it right, i guess i will have to modify the getvalueat and setvalueta methods also, but i have no clue as to how shoud i modify the same, for
using combobox.[/QB]
I think you are going in the right direction. this is just a fundamental method that needs to be overridden, there are various supporting methods like getPreferredSize, and a ling list of methods which you need to override if you want this kind of functionality, I would let you know once I get some time from my current assignment, its long time I have used them. If you are ready to wait then Ican send you a code also in one weeks time, I will have to recode everything once again.
As far as the problem regarding the selection, you need to create a TableCellEditor for sure, it has various support methods like isEditing, editingStart, editingEnd, etc, which will allow you to get a very fine control on the behaviour of your editor component. Once you have a separate renderer component properly in place, I dont think you need to override getValuAt method again. the renderer should take care of it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to add JCombox inside JtreeTable