• Post Reply Bookmark Topic Watch Topic
  • New Topic

dropdown arrow from my combo boxes do not show on my table.

 
Bor Kev
Greenhorn
Posts: 17
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am supposed to create a table and all components of the second column are combo boxes. When I click on the combo box cells I can access the combo boxes drop down menu fine. However , there is no way for the user to know that the cells are combo boxes unless they click on the corresponding cells. Below my code. Any suggestions? Thanks for your help.

 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JTable will display data using Renderers
Editing is done via Editors

What you are seeing
However , there is no way for the user to know that the cells are combo boxes

is the default renderer in action (which is just a JLabel instance display the value.toString();)

Solution: Provide a custom renderer which uses a JComboBox
Check out http://www.java2s.com/Tutorial/Java/0240__Swing/UsingaJComboBoxinaCellinaJTableComponent.htm
 
Bor Kev
Greenhorn
Posts: 17
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Manesh Godbole,

Thank you so much for your post. It worked !!

Sincerely,

bor_kev
 
Bor Kev
Greenhorn
Posts: 17
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Manesh Godbole,

Thanks for your reply the other day regarding how to render JCombo boxes in table cells.
I am facing a similar problem right now and although I am tweeking the Renderer in my code as much as I can I cannot seem to get around it. That is why I was wondering if you could have a look at my code and help me out please. So basically all I am seeing in the table display is the references to my comboboxes such as : RulesParameterJComboBox[,0,0,0x0,invalid,layout=com.sun.java.com.sun.java.swing.plaf.windows ..........


Her is the code for the domain class  :ResultCodesData



There is the code for : ResultCodesTableColumn

Please keep in mind that  RulesParameterJComboBox extends class JCombobox



code for the TableModel :



code for Table class




Also for some reason, I cannot select the cells individually , all I can select are the rows. Hope it helps.

Sincerely,

Bor_kev
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So basically all I am seeing in the table display is the references to my comboboxes such as : RulesParameterJComboBox[,0,0,0x0,invalid,layout=com.sun.java.com.sun.java.swing.plaf.windows ..........

What you are seeing is the string representation of the combo box which your getValue returns.
Solution: Make your getValue return the actual data values

Remember:
Renderer/Editor are the View
Model is the pure data

To rephrase,  data is new String[]{"A","B","C"};
View is a JComboBox instance
 
Bor Kev
Greenhorn
Posts: 17
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am sorry to insist but I do not understand your response. Which getValue method are you talking about? Are you talking about getValueAt method from the ResultCodesTableModel class or some getvalue method from the ResultCodesTable?

As far as the Model/View Concept is concerned, this is my understanding for tables :

the Table Model contains the actual data. This is why my ResultCodesTableModel contains two critical attributes :

1-  Vector<TableColumnData> : a vector (or collection) containing the table column names

2- Vector<T> : a vector (or collection) containing the actual data

In my case for testing purposes,  I hard coded the Table Model so that it actually contains all table columns names and the actual data.

Each row in my table will be a ResultCodesData :

Hence the code below :




The View for tables is taken care of by the JTable class, this is why my ResultCodesTable (which extends JTable) is as follows :



I have looked at many posts on forums and it looks like usually when there is a rendering issue - which in my case is a JCombox rendering issue - people should override the getCellRenderer method which I attempted but it does not work. This is why I do not understand what getValue method you are talking about. Could you please be more specific? there is no getValue method in the JTable class to override and there is getValueAt method in the table Model. If you are talking about the latter I do not know how to adjust it to reflect my actual data on the View (i.e when my Jtable is supposed to render my actual model). Thanks for your help.

Sincerely,

bor_kev






 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!