• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to add JCombox inside JtreeTable

 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have been struggling to add a jcomboox inside a jtreetable.
can anyone assist me with some code snippet.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
A teeny tiny vulgar attempt to get you to buy our stuff
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic