Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jframe , on resize throws exception

 
khaja mohideen
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

On reszie of jframe i.e. my masterframe , throws the following exception and main components ( jtable inside the jframe ) does not resize anymore and
i get the following messages. Please give me clue , to look for a solution

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.DefaultComboBoxModel.getElementAt(Unknown Source)
at javax.swing.plaf.basic.BasicComboBoxUI.getDisplaySize(Unknown Source)
at javax.swing.plaf.metal.MetalComboBoxUI.getMinimumSize(Unknown Source)
at javax.swing.JComponent.getMinimumSize(Unknown Source)
at java.awt.FlowLayout.minimumLayoutSize(Unknown Source)
at java.awt.Container.minimumSize(Unknown Source)
at java.awt.Container.getMinimumSize(Unknown Source)
at javax.swing.JComponent.getMinimumSize(Unknown Source)
at javax.swing.BoxLayout.checkRequests(Unknown Source)
at javax.swing.BoxLayout.preferredLayoutSize(Unknown Source)
at java.awt.Container.preferredSize(Unknown Source)
at java.awt.Container.getPreferredSize(Unknown Source)
at javax.swing.JComponent.getPreferredSize(Unknown Source)
at java.awt.BorderLayout.preferredLayoutSize(Unknown Source)
at java.awt.Container.preferredSize(Unknown Source)
at java.awt.Container.getPreferredSize(Unknown Source)
at javax.swing.JComponent.getPreferredSize(Unknown Source)
at java.awt.BorderLayout.layoutContainer(Unknown Source)
at java.awt.Container.layout(Unknown Source)
at java.awt.Container.doLayout(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validate(Unknown Source)
at javax.swing.RepaintManager.validateInvalidComponents(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.BoxLayout.preferredLayoutSize(Unknown Source)
at java.awt.Container.preferredSize(Unknown Source)
at java.awt.Container.getPreferredSize(Unknown Source)
at javax.swing.JComponent.getPreferredSize(Unknown Source)
at java.awt.BorderLayout.preferredLayoutSize(Unknown Source)
at java.awt.Container.preferredSize(Unknown Source)
at java.awt.Container.getPreferredSize(Unknown Source)
at javax.swing.JComponent.getPreferredSize(Unknown Source)
at java.awt.BorderLayout.layoutContainer(Unknown Source)
at java.awt.Container.layout(Unknown Source)
at java.awt.Container.doLayout(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validate(Unknown Source)
at javax.swing.RepaintManager.validateInvalidComponents(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Regards
kmm
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Please give me clue , to look for a solution

post your code (simplified version producing error)
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I doubt greatly that that Exception has anything to do with resizing.
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The exception is triggered by the resizing (as can be seen by all the layout manager calls in the stack trace), but my guess is that both the NullPointerException and ArrayIndexOutOfBoundsException are caused by updates to the GUI from a thread other than the EDT.
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I acknowledge my mistake, Rob.
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I checked out the code of BoxLayout.preferredLayoutSize which is causing the NullPointerException. There are three candidates there: a field called xTotal is null, a field called yTotal is null, or the component returns null from getInsets(). These two fields are set from private method checkRequests(), so these can't really be the problem. That leaves getInsets() returning null.

I'm 90% sure that the ArrayIndexOutOfBoundsException is caused by a threading issue. BasicComboBoxUI.getDisplaySize() only calls the combo box model's getValueAt method if the model's getSize() method returns a value > 0. DefaultComboBoxModel's getElementAt method is again protected against that:
So the only way that this ArrayIndexOutOfBoundsException could have occurred is if between the checking of the index and the retrieval of the element (between lines 2 and 3 of that code snippet) the model is changed. That can only occur if that's done by another thread, which means updating the model from a thread that isn't the EDT.
 
khaja mohideen
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

thank you for the replies , i am now analysing on basis of what you have suggested

just to add , this exception seems to occur only in some cases where i read a text file and update JTable( which is done inside a thread) inside the frame

after which . on resizing the mainframe , the jtable does not resize

regards
 
khaja mohideen
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi



// this is done in constructor
fsPanel = new JPanel();
//fsPanel.setLayout(new BorderLayout());
fsPanel.setLayout(new BoxLayout(fsPanel, BoxLayout.PAGE_AXIS));
fsPanel.add(filterPanel,"North");
fsPanel.add(timePanel);
fsPanel.add(searchPanel,"South");
---------------------------------------------------------

public void setPanelEnabled(boolean enabled){
for(int i = 0; i < fsPanel.getComponentCount(); i++){
JPanel compPanel = (JPanel) fsPanel.getComponent(i);
for(int j = 0; j < compPanel.getComponentCount(); j++){
compPanel.getComponent(j).setEnabled(enabled);
}
}
}



i write a method setPanelEnabled to enable/disable components of the panel ( which are checkboxes,comboboxes)

this method was causing the problem , i think there is something not clean in this code
as i am new to java , your insight will help me.

but any way thankyou for the replies which helped me to track the problem is short time.

Regards
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
khaja mohideen wrote:... ( which is done inside a thread) ...

Tutorial: Concurrency in Swing. Also, search the net for "Swing's single threaded rule"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic