java - Swingtools extension of JXTable and JTable, hiding columns return index out of bounds -
i'm evaluating swingtools jtable, open source , more powerful version of jtable , jxtable. maintainer ivan portyankin explains on blog ipsoftware blog:
"sometimes may seem standard swing jtable or close companions swingx jxtable limited. don’t have many funny ways manipulate them – strict rectangular grids, every row taking fixed amount of screen space in pixels , columns taken 1 , column model. columns cannot spanned or split , take single cell in grid."
now investigating ability of hiding columns, can done via interface: i'd hide default columns , store preference when user manually re-enables them show last chosen preference.
below try hide columns default incur in arrayindexoutofboundsexception
error!!
public class advancedtabledemo extends jframe { public advancedtabledemo() { super("advanced table demo"); setdefaultcloseoperation(exit_on_close); setsize(600, 300); final basetable basetable = new basetable(); basetable.setfilterheaderenabled(true); add(new jscrollpane(basetable)); beanpropertytablemodel<tablebean> model = new beanpropertytablemodel<tablebean>(tablebean.class); model.setorderedproperties(arrays.aslist("name", "surname", "date")); model.setdata(tablebean.generatelist(100)); basetable.setmodel(model); int j = basetable.getcolumncount(true); (int = 0; < j; i++) { tablecolumnext tablecolumnext = basetable.getcolumnext(i); tablecolumnext.setvisible(false); } setvisible(true); } public static void main(string[] args) { swingutilities.invokelater(new runnable() { @override public void run() { new advancedtabledemo(); } }); } }
the error is:
exception in thread "awt-eventqueue-0" java.lang.arrayindexoutofboundsexception: 2 >= 1 @ java.util.vector.elementat(vector.java:474) @ javax.swing.table.defaulttablecolumnmodel.getcolumn(defaulttablecolumnmodel.java:294) @ org.jdesktop.swingx.jxtable.getcolumn(jxtable.java:2265) @ org.jdesktop.swingx.jxtable.getcolumnext(jxtable.java:2415) @ demo.table.advancedtabledemo.<init>(advancedtabledemo.java:46) @ demo.table.advancedtabledemo$1.run(advancedtabledemo.java:62) @ java.awt.event.invocationevent.dispatch(invocationevent.java:311) @ java.awt.eventqueue.dispatcheventimpl(eventqueue.java:756) @ java.awt.eventqueue.access$500(eventqueue.java:97) @ java.awt.eventqueue$3.run(eventqueue.java:709) @ java.awt.eventqueue$3.run(eventqueue.java:703) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$javasecurityaccessimpl.dointersectionprivilege(protectiondomain.java:76) @ java.awt.eventqueue.dispatchevent(eventqueue.java:726) @ java.awt.eventdispatchthread.pumponeeventforfilters(eventdispatchthread.java:201) @ java.awt.eventdispatchthread.pumpeventsforfilter(eventdispatchthread.java:116) @ java.awt.eventdispatchthread.pumpeventsforhierarchy(eventdispatchthread.java:105) @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:101) @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:93) @ java.awt.eventdispatchthread.run(eventdispatchthread.java:82)
the column count 3, getting greater column 1 yields error seen! tried 17 columns , greater 10 returns exception.
am missing here??
the column count 3, getting greater column 1 yields error
int j = basetable.getcolumncount(true); (int = 0; < j; i++)
yes, after hide first column there 2. after hide next column there 1 (so exception).
so solution hide columns end of table, not beginning:
int j = basetable.getcolumncount(true) -1; (int = j; >= 0; i--)
Comments
Post a Comment