import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;


public class main implements ItemListener {


	String[] a = {"one","two","three"};
	String[] b = {"4","5","6"};
	String[] c = {"7","8","9"};
	String[] d = {"10","11","12"};
	String[] e = {"13","14","15"};
	JComboBox a1 = new JComboBox(a);
	JComboBox b1 = new JComboBox(b);
	JComboBox c1 = new JComboBox(c);
	
	main()
	{
		
		
				
		String[] col = {"ID","NAME","Address"};
		DefaultTableModel dt = new DefaultTableModel(col,100);
		JTable table = new JTable(dt);
		
		table.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(a1));
		table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(b1));
		table.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(c1));
		
		a1.addItemListener(this);
		b1.addItemListener(this);
		c1.addItemListener(this);
		
		JScrollPane js = new JScrollPane(table);
		JFrame f = new JFrame("Test");
		f.add(js);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setVisible(true);
		
	}
	
	public static void main(String[] args) {
		main m = new main();
		
	}

	
	public void itemStateChanged(ItemEvent e) {
		if(e.getSource() == a1)
		{
			
		}
		
	}

}

Problem is i want user to select column1 first then he choose column2 according to column1 and column3 then.... But above code is a free excel type you can select any column in any row.......

I have got link for that in your 2 two threads back ..., why did you tried to reinvent the wheel, maybe someone another will find patience for that, I'm out of this thread

Its because i m trying hard to get the logic.... I havent got a single answer yet which has explained things very clear......I just want a single explained answer.... :-(

i want user to select column1 first then he choose column2 according to column1 and column3

Can you explain what you are trying to do?
I select a row in column 1 and then select an item in the dropdown list. And then what?

Edited 5 Years Ago by NormR1: n/a

There are three combo boxes... a . b and c .... i have attached them with with jtable.
now there are choices in a combo box on which items are dependted on b combo box , e.g for choice "one" in a , b combo box contain 1,2,3. Problem is when if i select any choice in a combo box, the b combo box getitems not only in the row in which i m working but also in all table rows....

if i select any choice in a combo box, the b combo box getitems not only in the row in which i m working but also in all table rows

Sorry, I don't understand.
I select a row in column 1
A dropdown list shows: 'one', 'two', 'three
I select 'one'
"one" is placed in the box on that row in that column
Then what??? The table shows "one" in that row and column???

I know its difficult to understand by reading.... So i think posting a pic help you....
Take a look i can select data in multiple row, while i want to make dependent combo box , b depend on a and c on b.... but here i can select data freely. i want to restrict user to select data according to a combo box in that row ....

Attachments tets.JPG 9.01 KB

Is this what you want:
Don't allow any selection in column b or c until something is selected in column a.
When something is selected in column a then populate the selections for column b according to the selected item in column a.
The same dependency for column c on column b.

yes ... u got it man.... but also the it depend on that row column a not any column a value.....

it depend on that row column a not any column a value

Sorry, you lost me again. Can you explain what this means?

Do you mean: if you select a row in column a, you can only select that row in column b and then only that row in column c. The other rows in column b and c are disabled.

Edited 5 Years Ago by NormR1: n/a

take a look at previous pic... i selected column b and c in different rows while there column a is not selected.... so how they are dependent in that row....

Can you explain what was incorrect in my last post?
Or explain this:

the it depend on that row column a not any column a value....

Comments
thanx

for example i have three company microsoft, oracle and apple for column a , now for column b for micrsoft i have ms office , windows and sqlserver, for oracle oracle server,oracle dbms and oracle report server and for apple applesoftware, apple textpad and apple games.... for ms office in column c i have ms access , ms doc, and ms excel.

what happen if i select this combination

apple ->ms office -> ms access

its all because combo boxes are freely working.

Sorry, if neither of the ways I suggested are correct, then I have no more ideas on what you are trying to do.

pfizer ->mualim -> khost is correct
scilife->mualim->khost is wrong.... think like a software tester.

Attachments last.JPG 4.89 KB

correct one is pfizer->mualim->khost

wrong one is scilife->mualim->khost

its all because selecting pfizer populate the column b which can be selected from any row....

I didn't give you those choices. You ignored what I posted.

Can you rewrite this definition I gave earlier to be what you want?

Don't allow any selection in column b or c until something is selected in column a.
When something is selected in column a then populate the selections for column b according to the selected item in column a.
The same dependency for column c on column b.

i dont want user to select any choice in "b" until that row "a" is selected. same for c

Are you saying my last post is correct or that it is incorrect?

How does the row selected in column a relate to the choices of what row can be selected in column b?

yes...... i want user to select column a first in that row where he is selecting values

Loadshedding time is near here...... Thanx Norm for giving your precious time.... i will be back after an hour

So after selecting something in column a, the user can go to any other row in column b?
Or must he stay on the same row in column b?

This sounds to me like you want to disable all the cells in cols B and C until the user selects a cell in col A. At that point you want to enable just those cells in col B that are valid for the chosen value in Col A (ditto for B -> C).
Here's a link to how to use a custom cell renderer to achieve the disabling/enabling
http://www.coderanch.com/t/337047/GUI/java/JComboBox-Disabled-Items
(I assume you can work out your own logic for deciding which cells should be enabled)

Depending on the lengths of the lists it may be better GUI practice to hide/remove all invalid choices from cols B and C rather than having long drop-downs with mostly unavailable choices. This simply requires you to re-populate each list when the user makes a choice from the previous list.

Edited 5 Years Ago by JamesCherrill: n/a

user must stay in the same row and select another column........... until he selected column c he wont be able to go into another row...

Sorry, I don't understand the exact process either in that case. It certainly doesn't make sense in the light of the Apple/MS example you gave earlier, not does it sound like friendly GUI practice.

I have found a solution can any one code it....

If i select a value in column a at that time i will record it row number , when i will select value from column b i will match the row number if row number matches then values are listed else an empty column b

yes u right james it isnt friendly gui practice in which user can mess up the whole database... all i want that user must pass serially from column a to c in each row.

If i select a value in column a at that time i will record it row number , when i will select value from column b i will match the row number if row number matches then values are listed else an empty column b

how does the user select a row from column b if the values are only listed (or empty column) after the user ]makes the selection? What do you mean by "row number matches"?

it isnt friendly gui practice in which user can mess up the whole database

There's nothing user-friendly about a program that can mess up an entire database, that's just poor programming.
What you are saying is that if the user accidently selects "Apple" instead of "MS" he has to go on and select an Apple product in col b, the an Apple sub-product in col C before he can go back and correct his selection in col a. Well, OK, it's your program.

Edited 5 Years Ago by JamesCherrill: n/a

Yes its all my fault but all i need a solution... i thought java support each row with seperate combo box but its all column....

This question has already been answered. Start a new discussion instead.