The function to be implemented is to add check boxes to the table. You need to override the getcolumnclass () method of jtable. jtable supports check boxes by default, make sure that the values of the columns to be displayed as check boxes are Boolean and editable and the columns to be added are editable, it is generally implemented by rewriting the iscelleditable method of the data model corresponding to the jtable.
The error code is as follows:
Private jtable gettable () {<br/> If (Table = NULL) {<br/> table = new jtable () {<br/> Private Static final long serialversionuid = 1l; <br/> public class getcolumnclass (INT c) {<br/> return getvalueat (0, c ). getclass (); // error <br/>}< br/>}; </P> <p> table. setmodel (this. gettmtablehba (); <br/> table. setselectionmode (listselectionmodel. single_selection); // sets the selection mode (single choice) <br/> table. gettableheader (). setreorderingallowed (true); // allow sorting <br/> table. gettableheader (). setresizingallowed (true); // you can drag to change the column width. <br/>}< br/> return table; <br/>}
The error message is as follows:
Exception in thread "AWT-EventQueue-1" Java. lang. nullpointerexception <br/> at com. inspur. webManager. gui. server. panel. createhbapanel $1. getcolumnclass (createhbapanel. java: 206) <br/> at javax. swing. jtable. getcellrenderer (unknown source) <br/> at javax. swing. plaf. basic. basictableui. paintcell (unknown source) <br/> at javax. swing. plaf. basic. basictableui. paintcells (unknown source) <br/> at javax. swing. plaf. basic. basictableui. paint (unknown source) <br/> at javax. swing. plaf. componentui. update (unknown source) <br/> at javax. swing. jcomponent. paintcomponent (unknown source) <br/> at javax. swing. jcomponent. paint (unknown source) <br/> at javax. swing. jcomponent. paintchildren (unknown source) <br/> at javax. swing. jcomponent. paint (unknown source) <br/> at javax. swing. jviewport. paint (unknown source) <br/> at javax. swing. jcomponent. paintchildren (unknown source) <br/> at javax. swing. jcomponent. paint (unknown source) <br/> at javax. swing. jcomponent. paintchildren (unknown source) <br/> at javax. swing. jcomponent. paint (unknown source) <br/> at javax. swing. jcomponent. paintchildren (unknown source) <br/> at javax. swing. jcomponent. paint (unknown source) <br/> at javax. swing. jcomponent. paintchildren (unknown source) <br/> at javax. swing. jcomponent. paint (unknown source) <br/> at javax. swing. jcomponent. painttooffscreen (unknown source) <br/> at javax. swing. bufferstrategypaintmanager. paint (unknown source) <br/> at javax. swing. repaintmanager. paint (unknown source) <br/> at javax. swing. jcomponent. _ paintimmediately (unknown source) <br/> at javax. swing. jcomponent. paintimmediately (unknown source) <br/> at javax. swing. repaintmanager. paintdirtyregions (unknown source) <br/> at javax. swing. repaintmanager. paintdirtyregions (unknown source) <br/> at javax. swing. repaintmanager. seqpaintdirtyregions (unknown source) <br/> at javax. swing. systemeventqueueutilities $ componentworkrequest. run (unknown source) <br/> at java. AWT. event. invocationevent. dispatch (unknown source) <br/> at java. AWT. eventqueue. dispatchevent (unknown source) <br/> at java. AWT. eventdispatchthread. pumponeeventforfilters (unknown source) <br/> at java. AWT. eventdispatchthread. pumpeventsforfilter (unknown source) <br/> at java. AWT. eventdispatchthread. pumpeventsforhierarchy (unknown source) <br/> at java. AWT. eventdispatchthread. pumpevents (unknown source) <br/> at java. AWT. eventdispatchthread. pumpevents (unknown source) <br/> at java. AWT. eventdispatchthread. run (unknown source) <br/>
The following error is returned:
Private void initpaneldata (server) {<br/> object [] devicerowdata = new object [] {Boolean. true, "A", "B", "C", "D", "E", "F"}; // error <br/> This. gettmtablehba (). addrow (devicerowdata); <br/>}
First, the columns corresponding to the check box must be of the boolean type, and then the data must be filled in full and cannot be omitted. Even if the corresponding column does not have a value, it must be expressed with a null character.