java - Displaying just one value in JComboBox when one is selected -


hello :) need changing jcombobox in jtable. i'm new gui-programming , swing , couldn't solve problem: have change behavior of jcombobox.

you can see combobox in picture below. if "ja" selected there should "nein" option , other way around. cool if "nein" set per default. code written 1 student last semester , have difficulties adjust combobox have to.

table combobox

that's code snippet combobox gets initialized.

optionsinteger = new jcombobox<string>();     optionsinteger.additem("ja");     optionsinteger.additem("nein");     optionsinteger.setselecteditem(optionsinteger.getitemat(0));     optionsinteger.setselectedindex(1);     optionsinteger.setname("optionsinteger"); 

the combobox gets inserted jtable in method:

    public void repaintxtable(defaulttablemodel model,jtable table, int xamount, jscrollpane scrollpane,                                 jcombobox<string> optionsinteger) {      model.setrowcount(xamount);      th = table.gettableheader();     tcm = th.getcolumnmodel();     tcs = tcm.getcolumns();      tcs.nextelement().setheadervalue("");     tcs.nextelement().setheadervalue("lower");     tcs.nextelement().setheadervalue("upper");     tc = tcs.nextelement();     tc.setheadervalue("integer");      tc.setcelleditor(new defaultcelleditor(optionsinteger));      for(int i=0;i<xamount;i++)     {         model.setvalueat("x"+(i+1), i, 0);     }  } 

thank help.

in code, line

optionsinteger.setselecteditem(optionsinteger.getitemat(0)); 

sets default selection zeroth element (ja). line

optionsinteger.setselectedindex(1); 

sets default selection first element (nein).

either set selected item or selected index. there's no need both.

a jcombobox not remove selected element default. if selected element removed, how selected element display in jtable?

if want this, you'll have create own version of jcombobox.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -