Almira Bojani
Almira Bojani

Reputation: 579

Change value in column on select JComboBox

I have table with two columns and lot of rows, each column contain JComboBox. I wrap JComboBox into DefaultCellEditor and added to model. How to implement that when I choose in JComboBox ( example row=3 column=0) I set some value at JComboBox ( row=3 column =1)?

Upvotes: 3

Views: 545

Answers (3)

mKorbel
mKorbel

Reputation: 109823

please read this tutoriar http://download.oracle.com/javase/tutorial/uiswing/components/table.html#combobox example shows basic workaround for TableCellEditor, tons of examples for that http://www.java2s.com/Code/Java/Swing-JFC/CatalogSwing-JFC.htm subfolder http://www.java2s.com/Code/Java/Swing-JFC/Table-Renderer-Editor.htm

Upvotes: 1

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285430

A TableModelListener will let you be notified of changes in a cell's value. Once notified you use that information to change the value in your other cells via setValue as jzd mentions.

Upvotes: 1

jzd
jzd

Reputation: 23639

In your Table Model's setValue method, when you have a change in column 0 call setValue again for column 1 with the value you want in column 1.

Upvotes: 1

Related Questions