getColumnModel().removeColumn(getColumnModel()
.getColumn(modelIndex))
but after finishing off with my method i get an
exception as:
Exception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException: -1 < 0
at java.util.Vector.elementAt(Vector.java:427)
at javax.swing.table.DefaultTableColumnModel.getColumn(DefaultTableColumnModel.java:276)
at javax.swing.plaf.basic.BasicTableHeaderUI.getHeaderRenderer(BasicTableHeaderUI.java:341)
at javax.swing.plaf.basic.BasicTableHeaderUI.paintCell(BasicTableHeaderUI.java:352)
at javax.swing.plaf.basic.BasicTableHeaderUI.paint(BasicTableHeaderUI.java:333)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:39)
at javax.swing.JComponent.paintComponent(JComponent.java:398)
at javax.swing.JComponent.paint(JComponent.java:739)
at javax.swing.JComponent.paintChildren(JComponent.java:523)
at javax.swing.JComponent.paint(JComponent.java:748)
at javax.swing.JViewport.paint(JViewport.java:668)
at javax.swing.JComponent.paintChildren(JComponent.java:523)
at javax.swing.JComponent.paint(JComponent.java:748)
at javax.swing.JComponent.paintChildren(JComponent.java:523)
at javax.swing.JComponent.paint(JComponent.java:748)
at javax.swing.JComponent.paintChildren(JComponent.java:523)
at javax.swing.JComponent.paint(JComponent.java:748)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:546)
at javax.swing.JComponent.paintChildren(JComponent.java:523)
at javax.swing.JComponent.paint(JComponent.java:719)
at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:23)
at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:54)
at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:91)
at java.awt.Container.paint(Container.java:963)
at javax.swing.JApplet.update(JApplet.java:133)
at sun.awt.RepaintArea.update(RepaintArea.java:337)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:203)
at java.awt.Component.dispatchEventImpl(Component.java:2665)
at java.awt.Container.dispatchEventImpl(Container.java:1216)
at java.awt.Component.dispatchEvent(Component.java:2499)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:336)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:134)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:96)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:88)
what's going wrong? Another important question is how do i debug
the above kind of error for my application. I use JBuilder5.0 and
think the above error came while RepaintManager was doing it's job.
But i cannot figure out this for which component and why?
i can get over this by using the TableColumn.setMinWidth()/MaxWidth()
etc...
but still feel that earlier was the right way of doin it...
: andy
andy schrieb:
>
> hi folks,
> I have an extended JTableHeader class from where i
> manipulate the table columns. I got a default popup menu
> attached to this header. Within the popup, i have put
> "hide column" menu item. What i actually do for hiding
> column is remove the column from the TableColumnModel
> by invoking the removeColumn() method as:
>
> getColumnModel().removeColumn(getColumnModel()
> .getColumn(modelIndex))
>
hmm, getColumn(modelIndex) smells... if the name is an appropriate you
are using the wrong coordinate system (every access inside the
columnModel is in view coordinates). How do you get hold of that
modelIndex?
> but after finishing off with my method i get an
> exception as:
>
> Exception occurred during event dispatching:
> java.lang.ArrayIndexOutOfBoundsException: -1 < 0
> at java.util.Vector.elementAt(Vector.java:427)
This looks like modelIndex is -1 (which can be the case if you
calculated it by table's convertXXToYY(xxIndex)...
Greetings
Jeanette
> How do you get hold of that modelIndex?
Jeanette, the modelIndex is calculated as follows:
modelIndex = getColumnModel().
getColumn( columnAtPoint( e.getPoint() ).
getModelIndex();
> This looks like modelIndex is -1 (which can be the case if you
> calculated it by table's convertXXToYY(xxIndex)...
either way i calculate modelIndex, its obviously got to be the same...
eg:
System.out.println(" ind1 : " + getTable().
convertColumnIndexToModel( columnAtPoint( e.getPoint() )
+ " ind2 " + modelIndex );
will always return ind1=ind2
> if the name is an appropriate you are using the wrong coordinate system
> (every access inside the columnModel is in view coordinates).
can u elaborate on this?
: andy
andy schrieb:
>
> Jeanette, the modelIndex is calculated as follows:
> modelIndex = getColumnModel().
> getColumn( columnAtPoint( e.getPoint() ).
> getModelIndex();
>
> > This looks like modelIndex is -1 (which can be the case if you
>
> > if the name is an appropriate you are using the wrong coordinate system
> > (every access inside the columnModel is in view coordinates).
>
> can u elaborate on this?
Dont use the modelIndex to remove the column from the TableColumnModel,
use the index returned from columnAtPoint(p) directly - and read the api
doc of JTable which explains the coordinate systems...
Greetings
Jeanette